Archived topic
Category siblings stopped showing
14 replies · Started by Christos on August 4, 2021
In all category pages, category siblings stopped showing. Cache is cleaned. Nothing. ie.. https://mindfultravelexperiences.com/europe/
Hi. I found this code that works when added in functions.php
How to use Elements to add that exactly? When I did and set it to show in category_archive it just showed the code and not the result of it.
add_action( 'generate_after_archive_title', function() {
$term = get_queried_object();
$children = get_terms( $term->taxonomy, array(
'parent' => $term->term_id,
'hide_empty' => false
) );
if ( $children ) {
foreach( $children as $subcat ) {
echo 'taxonomy)) . '">' . $subcat->name . '';
}
}
} );
Hi there,
you won't need the first line of code:
add_action( ‘generate_after_archive_title’, function() {
or the last line:
} );
And you will need to wrap the code in code tags:
<?php
// code here
?>
And then check the Execute PHP option.
Unable to execute PHP as DISALLOW_FILE_EDIT is defined.
OK if . I removed the define('DISALLOW_FILE_EDIT', true); from wp config and the execute php got active. But...
The category siblings don't show neither all posts under the category. The only way all work is if I set the complete script in functions.php (without the hook)
I cleaned up your code, not sure if it got scrambled when pasted into the forum ( NOTE: When adding code in the forum, select the code, and hit the CODE button before submitting ) and added it to a Hook Element:
<?php
$term = get_queried_object();
$children = get_terms( $term->taxonomy, array(
'parent' => $term->term_id,
'hide_empty' => false
) );
if ( $children ) {
foreach( $children as $subcat ) {
echo 'taxonomy ' . '>' . $subcat->name . ' ';
}
}
?>
Hook set to: generate_after_archive_title
Display Rules: All Archives.
And that worked for me.
Doesn't work. Just shows the names of siblings with ">" i.e. sibling>sibling> and without being active. Still the code pasted in the functions.php works though.
I can't explain what the difference is.
The code you provided simply outputs a list of the child terms for the current archive term. And that worked for me.
It don't do anything more than that. Perhaps you have some other function that is doing something else ?
Hi. After the latest GP update, the code above stopped working.
It produces the following as siblings:
taxonomy >Austria taxonomy >Belarus taxonomy >Croatia taxonomy >Czech Republic taxonomy >Denmark taxonomy >France taxonomy >Germany taxonomy >Greece taxonomy >Hungary taxonomy >Iceland taxonomy >Ireland taxonomy >Lithuania taxonomy >Malta taxonomy >Netherlands taxonomy >Poland taxonomy >Portugal taxonomy >Slovakia taxonomy >Slovenia taxonomy >Spain taxonomy >Switzerland taxonomy >Travel to Italy taxonomy >United Kingdom
Why?
Hm. I solved it by adding the following but why it is deactivated on GP update?
<?php
if (is_category()) {
$this_category = get_category($cat);
}
?>
<?php
if($this_category->category_parent)
$this_category = wp_list_categories('orderby=id&show_count=0
&title_li=&use_desc_for_title=1&child_of='.$this_category->category_parent.
"&echo=0"); else
$this_category = wp_list_categories('orderby=id&depth=1&show_count=0
&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID.
"&echo=0");
if ($this_category) { ?>
<ul>
<?php echo $this_category; ?>
</ul>
<?php } ?>
Where did you add the that snippet originally ?
If were in the Parents Theme functions.php then that would have been overwritten when the theme updated.
It is added as an Elements block
I can't explain what happened on update - but is it working now ?
It works but I had to add a different script. not the previous one.
There isn't anything in that code that is GP specific, its using 100% core functions, so the update shouldn't have affected it. Glad to hear you found a working solution though!