Site logo

Archived topic

display related categories in the parent category

13 replies · Started by simone on September 6, 2019

Viewing posts 1–14 of 14

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

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

Hi there,

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

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

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>

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?

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

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

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

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>

Good morning, perfect thanks

You're welcome :)

This archived topic is closed to new replies.