• Resolved ikramy

    (@ikramy)


    Hi,

    I have 3 levels navigation on my site as the following:

    — Page 1.1 (level 1)
    — Page 1.2 (level 1)
    —- Page 1.2.1 (level 2)
    —- Page 1.2.2 (level 2)
    —— Page 1.2.2.1 (level 3)
    —— Page 1.2.2.2 (level 3)
    —— Page 1.2.2.3 (level 3)

    What I want on one of my pages is to ONLY display the pages in the 3rd level. How can I do that?

    [title moderated]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter ikramy

    (@ikramy)

    Thanks for the answer, but what I really wanted is to list all the 3rd level pages rather than listing the pages of parent ID 3.

    Maybe the long road there but try:

    <?php
    $gen1 = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent = 0  AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
    $gen1_ids = implode($gen1,', ');
    $gen2 = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN ($gen1_ids) AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
    $gen2_ids = implode($gen2,', ');
    $gen3 = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN ($gen2_ids) AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
    $gen3_ids = implode($gen3,', ');
    wp_list_pages('include=' . $gen3_ids . '&title_li=<h2>' . __('Level 3 Pages') . '</h2>');
    ?>

    The nested queries approach above seems like a good route– probably better than using nested foreach statements and only outputting the third iteration of wp_list_pages(“child_of=$previousgen”).

    Thread Starter ikramy

    (@ikramy)

    Thanks guys, I also tried this, and it works

    <?php
    $string = wp_list_pages('title_li&echo=0');
    if (preg_match('#^.*?<ul>.*?<ul>.*?(\s*<ul>.*?</ul>)#is', $string, $matches))
    {
        echo $matches[1]."\n";
    }
    
    ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘ONLY display the pages in the 3rd level’ is closed to new replies.