To get list of bottom most or deepest or last child for specified parent category

admin2025-06-05  1

I want to list all the last deepest / bottom most childs of a specified parent category in a page. the structure is

  • Parent A

    • child 1

      • grand child 1
    • child 2

      • grand child 2

        • great grand child 1
    • child 3

      • grand child 3

... I need to list all the last childs of specified parent, say for above example i need list for ParentA and the results should be like this

  • grand child 1
  • great grand child 1
  • grand child 3

is there any code to display in a page. I'm new to wp and PHP. Thanks in advance

I want to list all the last deepest / bottom most childs of a specified parent category in a page. the structure is

  • Parent A

    • child 1

      • grand child 1
    • child 2

      • grand child 2

        • great grand child 1
    • child 3

      • grand child 3

... I need to list all the last childs of specified parent, say for above example i need list for ParentA and the results should be like this

  • grand child 1
  • great grand child 1
  • grand child 3

is there any code to display in a page. I'm new to wp and PHP. Thanks in advance

Share Improve this question asked Dec 5, 2018 at 20:31 Selva KumzzSelva Kumzz 113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can use wp_list_categories to achieve that:

<ul>
    <?php
        wp_list_categories( array(
            'child_of' => <PARENT_ID>, // show only children of PARENT_ID
            'childless' => true, // show only categories without children
            'hide_empty' => true, // should empty categories be hidden
        ) );
    ?> 
</ul>

You can find full list of available params here: https://developer.wordpress/reference/classes/wp_term_query/__construct/#parameters

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749125525a316580.html

最新回复(0)