- This topic has 13 replies, 3 voices, and was last updated 5 years, 2 months ago by Tom.
-
AuthorPosts
-
September 6, 2019 at 9:49 am #1002757simone
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
September 6, 2019 at 4:29 pm #1002971TomLead DeveloperLead DeveloperHi 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/
September 7, 2019 at 1:08 am #1003095simonehello, that plugin is not good because you have to set the parent category, while I would like it to be displayed automatically
September 7, 2019 at 5:00 am #1003183DavidStaffCustomer SupportHi there,
can you confirm that you want to display the list of Child Categories in the Sidebar ?
September 7, 2019 at 5:44 am #1003206simoneHi, 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
- –Componenti
- –Wiki Pc
- -Installare sistema operativo
-Ottimizzare il pc
-Sicurezza informatica
-Utility Pc –
- -Installare sistema operativo
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 DesktopSeptember 7, 2019 at 3:46 pm #1003626TomLead DeveloperLead DeveloperI 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.September 8, 2019 at 12:56 am #1003811simonegood 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>
September 8, 2019 at 9:27 am #1004145TomLead DeveloperLead DeveloperWhen 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?
September 8, 2019 at 9:31 am #1004149simoneit is correct, but I would like them to see their sub-categories as in the aranzulla site.
September 8, 2019 at 4:13 pm #1004348TomLead DeveloperLead DeveloperSo if those child categories have child categories, you want to display them as well? How deep are you wanting to go?
September 8, 2019 at 10:39 pm #1004455simoneHi, I want to display them and I would like to go to the depth of 1 level
September 9, 2019 at 9:20 am #1004955TomLead DeveloperLead DeveloperIt 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>
September 9, 2019 at 10:30 pm #1005398simoneGood morning, perfect thanks
September 10, 2019 at 9:28 am #1005961TomLead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.