Commit 731cb33b authored by Bruno Antunes Magrini's avatar Bruno Antunes Magrini
Browse files

adiciona alguns testes no loop e alterações no edit.js

parent d444631b
......@@ -54,40 +54,31 @@ function render_block_core_post_terms_2($attributes, $content, $block)
$tax_terms = [];
if (is_taxonomy_viewable($taxonomy)) {
$tax_terms = get_the_terms($block->context['postId'], $taxonomy);
$post_terms = array_merge($post_terms, $tax_terms);
if (is_array($tax_terms)){
$post_terms = array_merge($post_terms, $tax_terms);
}
}
}
if (is_wp_error($post_terms) || empty($post_terms)) {
return '';
}
if (isset($attributes['textAlign'])) {
$classes .= ' has-text-align-' . $attributes['textAlign'];
}
$separator = empty($attributes['separator']) ? ' ' : $attributes['separator'];
$wrapper_attributes = get_block_wrapper_attributes(array('class' => $classes));
echo '<pre>';
print_r($post_terms);
echo '</pre>';
$html_array = [];
foreach ($post_terms as $term) {
// The $term is an object, so we don't need to specify the $taxonomy.
$term_link = get_term_link($term);
// If there was an error, continue to the next term.
if (is_wp_error($term_link)) {
continue;
$html = '';
if(count($post_terms)){
$separator = empty($attributes['separator']) ? ' ' : $attributes['separator'];
$wrapper_attributes = get_block_wrapper_attributes(array('class' => $classes));
$html_array = [];
foreach ($post_terms as $term) {
// The $term is an object, so we don't need to specify the $taxonomy.
$term_link = get_term_link($term);
// If there was an error, continue to the next term.
if (is_wp_error($term_link)) {
continue;
}
// We successfully got a link. Print it out.
$html_array[]= '<a clases="post-term-' . $term->slug . ' post-taxonomy-' . $term->taxonomy .' " href="' . esc_url($term_link) . '">' . $term->name . '</a>';
}
// We successfully got a link. Print it out.
$html_array[]= '<a clases="post-term-' . $term->slug . ' post-taxonomy-' . $term->taxonomy .' " href="' . esc_url($term_link) . '">' . $term->name . '</a>';
$html = implode($separator, $html_array);
}
$html = implode($separator, $html_array);
return $html;
}
......@@ -28,7 +28,7 @@ import {
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { store as coreStore } from '@wordpress/core-data';
import ServerSideRender from '@wordpress/server-side-render';
/**
* Internal dependencies
*/
......@@ -42,7 +42,6 @@ export default function Edit(props) {
const { postId, postType } = context;
const ctaxblock = window.ctaxblock
const taxonomies = ctaxblock.taxPerPt[postType]
console.log(selectedTax);
const selectedTerm = useSelect(
(select) => {
if (!term) return {};
......@@ -96,34 +95,7 @@ export default function Edit(props) {
</PanelBody>
</Panel>
</InspectorControls>
<div {...blockProps}>
{isLoading && <Spinner />}
{!isLoading &&
hasPostTerms &&
postTerms
.map((postTerm) => (
<a
key={postTerm.id}
href={postTerm.link}
onClick={(event) => event.preventDefault()}
>
{unescape(postTerm.name)}
</a>
))
.reduce((prev, curr) => (
<>
{prev}
<span className="wp-block-post-terms__separator">
{separator || ' '}
</span>
{curr}
</>
))}
{!isLoading &&
!hasPostTerms &&
(selectedTerm?.labels?.no_terms ||
__('Term items not found.'))}
</div>
termos de taxonomia
</div>
);
}
\ No newline at end of file
......@@ -58,7 +58,6 @@
setAttributes,
} = props;
console.log( props );
const {
titleBlock,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment