list only second level pages
-
Hi all,
How can I list only 2nd level pages?
Independently of being on a 1st, 2nd or 3rd level page.Thanks for your help guys.
-
list level2 pages
<?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,', '); wp_list_pages('include=' . $gen2_ids . '&title_li=<h2>' . __('Level 2 Pages') . '</h2>'); ?>It worked!
Thank you very much!
I have a problem I didn’t notice before.
When I’m in a 3rd level page this code lists all 2nd level pages and not only the ones in the same tree as the current page.
What do I need to change to get the right behavior?
Thanks for your help again.
Not sure this is what you are asking but it will list “level3” pages
<?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>'); ?>Thank for your answer. Sorry I didn’t make it clear.
I have a structure like this:
level 1a
-level 2a
-level 2b
level 1b
level 1c
-level 2c
–level 3a
–level 3b
-level 2dwhen I’m at “level 3a”, for instance, it lists all level 2 pages (2a,2b,2c & 2d) instead of just the ones in the same tree (2c & 2d).
I have one different DIV for each level.
Thank you again!
Not sure about that, but at the least, you will need to paste your complete template (is it page.php?) at wordpress.pastebin.ca and report the link back here.
Hi guys! I think I have an almost identical problem or at least very very similar: I want the same page list to appear regardless of what level in the hierarchy I’m on. Right now I’m using this code:
<?php if($post->post_parent) $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&sort_column=menu_order"); else $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&sort_column=menu_order"); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php } ?>This shows me all child pages of the current top-level parent, but one section (one list item) has another deeper level (its own sublist), and when on one of those pages, I only get that level’s pages listed. I’d like the same exact list when on all pages (of the top-level parent).
Is that clear? Let me know… and thank you!
Adam
The topic ‘list only second level pages’ is closed to new replies.