Exclude Current Page from wp_list_pages
-
I want to display a list of links to child pages, but I want to exclude the current page being viewed. I have been all over the codex and forums, and as yet have no solution to this.
Here is my existing code:
<?php if($post->post_parent) $children = wp_list_pages("title_li=&depth=1&child_of=".$post->post_parent."&echo=0"); else $children = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0"); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php } ?>
This works perfectly to show the child pages, and only the child pages, when on a parent or on one of the children. (This is straight from codex.) However, it shows a link to the current page, which is undesirable. I realize I could use exclude=ID, but then I’d have to write a zillion if statements. I don’t want to use a hardcoded page ID.
What I want is a clean solution that simply excludes the page we’re on….I thought I could just add
exclude=".$post->ID."
or something to that effect….but I’m no PHP coder, and no variation of this seems to work. Either it displays the list just as it is, no effect — or it breaks the menu.Can someone please tell me the correct php code to fit the above existing code?
Thanks in advance!
- The topic ‘Exclude Current Page from wp_list_pages’ is closed to new replies.