• Have a problem with that show children and grandchildren in different blocks, but can not find any good way to do this. Is there a good way for this. All I come up with is that the main menu and its children in different blocks. But the grandchildren are nested.

    Here’s how it looks:

    <ul class="menu top_level">
    	<li>Parent 1</li>
    	<li>Parent 2</li>
    	<li>Parent 3</li>
    	<li>Parent 4</li>
    	<li>Parent 5</li>
    	<li>Parent 6</li>
    </ul>
    
    <ul class="menu subpages">
    	<li>Child 1</li>
            <li class="current_page_item">Child 2
                  <ul class="children">
    	        <li class="page_item">Grandchild</li>
                  </ul>
            </li>
    	<li>Child 3</li>
    </ul>

    And I want it like this:

    <ul class="menu top_level">
    	<li>Parent 1</li>
    	<li>Parent 2</li>
    	<li>Parent 3</li>
    	<li>Parent 4</li>
    	<li>Parent 5</li>
    	<li>Parent 6</li>
    </ul>
    
    <ul class="menu subpages">
    	<li>Child 1</li>
            <li class="current_page_item">Child 2</li>
    	<li>Child 3</li>
    </ul>
    
    <ul class="children">
    	<li class="page_item">Grandchild</li>
    </ul>

    Is this possible?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The closest you’re going to get is probably this:

    <ul>
    <?php wp_list_pages('title_li=&depth=1');?>  Show only top level pages
    </ul>
    
    <ul>
    <?php wp_list_pages('title_li=&child_of=2');?> Show only childen of Page 2
    </ul>
    
    <ul>
    <?php wp_list_pages('title_li=&child_of=3');?> Show only childen of Page 3
    </ul>

    First, show only the top level pages.

    Then show the children of the Page with an ID of 2

    Then show the children of the Page with an ID of 3

    I don’t know how your Pages are currently arranged (hierarchy-wise) but it might be a case of ‘faking it’ a bit by creating subpages of ID2 that you know in your mind are child Pages, and subpages of ID3 that you know in your mind are grandchild Pages.

    the question is generally very complex, as each page could have several child-pages, which in turn could have several child-pages themselves (the grandchildren) – making the whole system a tree like feature;

    in the first step you would need to list the top parent pages;
    then foreach of the top parent pages the child pages;
    then foreach of the child pages their children (i.e. grandchildren of the top parents).

    a bit like @richarduk’s idea – just dynamic.

    here is a hack https://wordpress.pastebin.com/tEUkqBXT which does this using a lot of string magic with wp_list_pages() – and separates the pages in three arrays with ‘parents’ childs’ ‘grandchilds’
    keeping the css classes and list structure of the original wp_list_pages

    ps: my html output is different from your idea; but that is in the last 9 lines of the code and easy to tweak.

    Thread Starter eonlova

    (@eonlova)

    hmm maby I do it wrong but I can’t see the menu with that script. Or do I have to add something to it.

    that script is a function and goes into functions.php of the theme;

    in your file where you want to see the output, you need to call the function with this line:

    <?php page_generation_lists(); ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘show children and grandchilds in different blocks’ is closed to new replies.