Problem with conditional tag in sidebar
-
Hi,
I’m having trouble getting this sidebar code to work and I’ve probably overlooked something obvious – but can’t see it. The idea is to display a list of sub-pages when on a Page, and a list of recent posts (code calls Recent Posts plugin function) when anywhere else. Works fine when not on a Page but returns nothing at all, ie no list of sub-pages – just blank space, when on a Page.
<?php if ( is_page()) { // We're on a Page so display a list of subpages assigned to this page ?> <div class="posts"> <?php if($post->post_parent) $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php } ?> </div> <?php } else // We're not on a Page so display a list of recent posts {; ?> <div class="posts"> <ul id="recentposts"> <li id="recent-posts"> <h2><?php _e('Recent Articles', "text_domain"); ?></h2> <?php recent_posts(); ?> </li> </ul> </div> <?php }; ?>
Some extra info:
There are no widgets called by the sidebar.
I don’t get any php errors, so the syntax must be ok (I guess, well, at least it isn’t giving me any php errors in the browser).
The Page I’m testing this on has 2 sub-pages.What am I missing/doing wrong?
Thanks!
Ade.
- The topic ‘Problem with conditional tag in sidebar’ is closed to new replies.