[Resolved] How to add Sibling Child Categories to the Category Header

Home Forums Support How to add Sibling Child Categories to the Category Header

  • This topic has 4 replies, 2 voices, and was last updated 1 month ago by Tom.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1261133
    medialinepublishing@outlook.com

    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

    #1262086
    Tom
    Lead Developer
    Lead Developer

    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.

    #1262661
    medialinepublishing@outlook.com

    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

    #1262712
    medialinepublishing@outlook.com

    ah, got it to work with code snipets…thanks for the help 🙂

    #1263481
    Tom
    Lead Developer
    Lead Developer
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.