How to customize the sidebar for pages and categories?
-
Please look at my site here. Also, please realize I am not a really good coder, I just copy and paste a lot, and try to see how things work and then change them.
For the top-menu, I used the following code:
<ul id="menu"> <li><a href="<?php bloginfo('url'); ?>">Home</a></li> <li><a href="<?php echo get_category_link($blog_category_page); ?>">Blog</a></li> <?php wp_list_pages('title_li=&depth=1' ); ?> </ul>
This should make a ‘home’ link, links for all parent pages and a link for one category, which is my blogpage. To make this work, I also added a config.php with the following code, because my blog is category 1:
<?php // blog category page $blog_category_page = 1; // category id ?>
This is all good, and exactly how I want my site to work. I want some pages, and one blogsection. Now come the problem: I also have a sidebar that appears everywhere, on the pages and on the blogcategory. I have the following code on sidebar.php:
<ul><?php if($post->post_parent){ $parent=get_post($post->post_parent); $children = '<li><a href="'.get_permalink($post->post_parent).'">'.$parent->post_title.'</a></li>'; $children .= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); }else{ $children = '<li><a href="'.get_permalink($post).'">'.$post->post_title.'</a></li>'; $children .= wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); } echo $children; ?> </ul>
this makes the parent page appear in a menu, including all child pages. So far, everything is OK! But I also have the following code in the sidebar.php:
<h2>Categories</h2> <ul> <?php wp_list_cats('sort_column=name&optioncount=0'); ?> </ul> </div> <div style="margin-bottom:10px;"> <h2>Archives</h2> <ul> <?php get_archives(); ?> </ul>
This shows the archive and the categories. This is no problem on the blogcategory (clicking blog in the topmenu), since they belong there, but on the other pages, I do not want this to appear. How can I do this?
So, to sum up: I have one category ‘blog’, and some parent pages in my menu. On the pages, I do not want the archive and category links in the sidebar. On the blog, they are fine. Can I exclude these pages somehow?
If anyone needs more info, just ask. If someone is available to help, I can always send some files.
- The topic ‘How to customize the sidebar for pages and categories?’ is closed to new replies.