Site logo

Archived topic

How to add Sibling Child Categories to the Category Header

4 replies · Started by Forum User on April 29, 2020

Viewing posts 1–5 of 5

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:

https://prnt.sc/s816p7

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:

https://prnt.sc/s8jhjt

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! :)

This archived topic is closed to new replies.