Cyber Monday Sale!

Save up to $50 through December 5th.

Shop Now

[Resolved] display related categories in the parent category

Home Forums Support [Resolved] display related categories in the parent category

Home Forums Support display related categories in the parent category

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1002757
    simone

    hello everybody I would like to visualize through the hook the child categories of the category that I am displaying.

    I followed this guide, (https://generatepress.com/forums/topic/displaying-sub-categories-on-parent-category-page/) but it’s not perfect for what I want to do.

    In my case, I would like the child categories to be displayed this way when I view the computer category.

    Accessori

    Hardware > Componenti > Configurazioni pc gaming > monitor > pc portatili e desktop

    Wiki pc > installare sistema operativo > ottimizzare il pc > sicurezza informatica > etc…

    practically like Aranzulla does in his blog https://www.aranzulla.it/computer

    #1002971
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Just so I understand – are you wanting to display a list of child category items in your sidebar when viewing a parent category?

    If so, maybe this is worth checking out?: https://wordpress.org/plugins/sub-categories-widget/

    #1003095
    simone

    hello, that plugin is not good because you have to set the parent category, while I would like it to be displayed automatically

    #1003183
    David
    Staff
    Customer Support

    Hi there,

    can you confirm that you want to display the list of Child Categories in the Sidebar ?

    #1003206
    simone

    Hi, I’d prefer below the category title like it is now (via hook), but if it’s really not possible in the sidebar.

    I wish that when I click on a parent category the sub-categories are displayed in this way.

    I give a practical example.

    If I click on the computer category from home, I want the sub-categories to be displayed in this way.

    • Accessori
    • Hardware
      • –Componenti
        –Configurazioni pc gaming
        –Monitor
        –Pc Portatili e Desktop
    • –Wiki Pc
      • -Installare sistema operativo
        -Ottimizzare il pc
        -Sicurezza informatica
        -Utility Pc –

    if I then click on the Hardware category I want only its sub-categories to be displayed
    -Componenti
    -Configurazioni pc gaming
    -Monitor
    -Pc Portatili e Desktop

    #1003626
    Tom
    Lead Developer
    Lead Developer

    I wonder if something like this would do it?: https://wordpress.stackexchange.com/a/33656

    You would add that to a Hook Element, and set it to the after_archive_title hook.

    #1003811
    simone

    good morning, it doesn’t work.

    I am currently using this code, but it shows me only the higher categories, but not the daughters

    <div class="display-category"><p>
    	<?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 '<a href="' . esc_url(get_term_link($subcat, $subcat->taxonomy)) . '">' . $subcat->name . ' - </a>';
            }
        }
    ?>
    	</p></div>
    #1004145
    Tom
    Lead Developer
    Lead Developer

    When I go to the Computer category, I see these three links:

    Accessori – Hardware – Wiki Pc

    Those seem to be child categories of the “Computer” category, no?

    #1004149
    simone

    it is correct, but I would like them to see their sub-categories as in the aranzulla site.

    #1004348
    Tom
    Lead Developer
    Lead Developer

    So if those child categories have child categories, you want to display them as well? How deep are you wanting to go?

    #1004455
    simone

    Hi, I want to display them and I would like to go to the depth of 1 level

    #1004955
    Tom
    Lead Developer
    Lead Developer

    It currently displays 1 level. If you want to go 2, you could try this:

    <div class="display-category">
        <p>
        <?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 '<a href="' . esc_url(get_term_link($subcat, $subcat->taxonomy)) . '">' . $subcat->name . ' - </a>';
    
                $grandchildren = get_terms( $subcat->taxonomy, array(
                    'parent'    => $subcat->term_id,
                    'hide_empty' => false
                ) );
    
                foreach ( $grandchildren as $grandchild ) {
                    echo '<a href="' . esc_url(get_term_link($grandchild, $grandchild->taxonomy)) . '">' . $grandchild->name . ' - </a>';
                }
            }
        }
        ?>
        </p>
    </div>
    #1005398
    simone

    Good morning, perfect thanks

    #1005961
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.