sidebar lists categories pagebound
-
Please look at http://www.customizen.nl, then click ‘over ons’ in the top menu
And look at http://www.risermedia.com and click ‘about’ in the top menu.
The first is my own, the second is what I want to achieve. What I want, is to make pages that have the parent ‘over ons’, and let the links to these pages appear in the sidebar. But how do I do that? Because I am not good with wordpress or php, if anyone knows the answer, please explain this very easily.
To sum up: I have a site with, say, 6 pages now. When you navigate to a page, in the top menu, you should go there, and see a content left part, and a sidebar which lists subpages. What is the code to get those subpages??
-
The code to do this is
wp_list_pages();which you will need to copy and paste in to your sidebar. The pages will display as a list. Only pages underneath 2 (which is your about page) will be displayed.The exact code you need is:
<?php if($post->post_parent) // this is a subpage so link to the parent $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else // this is the top page so link to the children, if they exist $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php }; ?>NB. Wherever you see
&you need to change it to&Read this for more help with the function
wp_list_pages()or reply.Hello there, bsutcliffe, I used:
<?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 } ?>This is the same as yours? I found it (luckily) in the supportfiles. It works great! But there is one problem: now the headermenu is screwed up! My menu looks like the following, I think (I didn’t make it myself):
<div id="header"> <div id="top"> <a href="<?php bloginfo('url'); ?>"><h1><span><?php bloginfo('name'); ?></span></h1></a> <ul id="menu"> <?php wp_list_pages('title_li=' ); ?> <li><a href="<?php echo get_category_link($blog_category_page); ?>">Blog</a></li> <li><a href="<?php bloginfo('url'); ?>">Home</a></li> </ul> <br class="clear" /> </div>How can I get subcategories to stay out of this menu? Now the lay-out (as you can see at www customizen . nl – the page ‘over ons’ has a subpage called ‘Hello’) is screwed!
I hope you can help with this!
Replace
<?php wp_list_pages('title_li=' ); ?>with
<?php wp_list_pages('title_li=&depth=1' ); ?>This will allow only top level pages to display. Let me know how you get on.
bsutcliffe, it works great! The problem is gone. I just have one more question. Is there a way to add the parent_page in the sidebar menu? It should also be clickable, so when you are on a childpage, you should be able to get back to the parentpage through the sidebar-menu!
The topic ‘sidebar lists categories pagebound’ is closed to new replies.