• Resolved felipewatanabe

    (@felipewatanabe)


    Hello!

    I’m running a WordPress based site and most of it’s pages have a navigation menu on the left side. I use it to list the all subpages within a parent page.

    Here’s one example: Tapps

    I currently manage that listing manually using the following code:

    <?php
    if ( is_page(array('parent', 'child1', 'child2', 'child3'))) {
    	wp_list_pages( 'child_of=1&link_before=<span class="submenu-nav-item">&link_after=</span>&title_li=' );
    } else {
    	echo "error";
    }
    ?>

    The is_page lists the parent page and it’s childs, so whenever I’m on the parent page or one of it’s childs, I have that menu on the left side.

    The problem is that every time I create a new child page, I have to add a new item in the array.

    Is there an easy way to make WP list my parent page and it’s childs so I do not have to do it manually every time?

    I think it’s silly question, but I couldn’t figure it out yet.

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Thread Starter felipewatanabe

    (@felipewatanabe)

    Hey.

    Figured out a way to do it, hope it helps anyone that comes around the same question.

    My piece of code:

    $section_childs = get_pages('child_of=1');
    $section_pages = array(1);
    foreach($section_childs as $section_child) {
    	array_push($section_pages,$section_child->ID);
    }
    
    if ( is_page($section_pages)) {
    	wp_list_pages( 'child_of=1&title_li=' );
    } else {
    	echo "error";
    }

    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘How to get a formatted array of all child pages of a parent page’ is closed to new replies.