Get parent pages or child pages (if exists)
-
Hi, I’m veeeery new to wordpress, with very basic knowledge of php.
That said ;), I can’t achieve something without using plugins that should be (I geuss) very easy to do in wp.I would like to have a sidebar menu that:
1 When visiting main page, all top level pages are listed in the sidebar.
2 When visiting a top level page with no children, all top level pages are listed.
3 When visiting a top level page with children, just the children pages, and descendant pages, are listed.I currently use this code, but it only does the #3.
Here is the code:
<?php /*MASSS Display child pages with thumbnail if exists*/ if (is_page( )){$childPages = get_pages(array('child_of' => $post->ID));} else {$childPages = get_pages( 'include=9' );} ?> <ul id="sidebar-childs"> <?php foreach ($childPages as $childPage): ?> <li> <a href="<?php echo get_page_link( $childPage->ID ); ?>"> <?php echo get_the_post_thumbnail($childPage->ID, 'thumbnail'); ?><h3><?php echo $childPage->post_title; ?></h3></a> </li> <?php endforeach; ?> </ul> <?php wp_reset_query(); /*MASSS END*/ ?>
(hope the `backticks work! it’s my first message, sorry)
Any help would be great!!! It’s days I’m trying to this! Thanks!!!!
- The topic ‘Get parent pages or child pages (if exists)’ is closed to new replies.