Archived topic
How to add Sibling Child Categories to the Category Header
4 replies · Started by Forum User on April 29, 2020
Hello,
I would like to add two things to the category header:
1. List of the subcategories (sibling categories)
2. A way to sort the posts in a category by date and popularity
it is something like you can see in the screenshot below:
thanks
Hi there,
To list the categories, you might be able to do something like this:
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 '<a class="button" href="' . esc_url(get_term_link($subcat, $subcat->taxonomy)) . '">' . $subcat->name . '</a>';
}
}
} );
The filters would likely require custom development as it's quite complex.
Thanks Tom... I am very new to wordpress... i placed that as an Element ... i see it on the category pages but it prints as is ... as in the image below:
Can you please just hint me into the right direction where to put this?
Thanks again
ah, got it to work with code snipets...thanks for the help :)
No problem! :)