• Resolved dekraan

    (@dekraan)


    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=&amp;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=&amp;child_of=".$post->post_parent."&amp;echo=0");
      }else{
        $children = '<li><a href="'.get_permalink($post).'">'.$post->post_title.'</a></li>';
        $children .= wp_list_pages("title_li=&amp;child_of=".$post->ID."&amp;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&amp;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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Look at the WordPress Default theme’s wp-content/themes/default/sidebar.php and how it uses Conditional Tags to not display ‘the meta’ and ‘blogroll’ on anything but the home page and Pages.

    Thread Starter dekraan

    (@dekraan)

    Hello MichaelH! I used

    <?php if(is_page()) { ?>
    <?php } ?>

    for the first part, so that the parent_page and children only appear on a page (might change this later, I don’t know if the titles of the posts will still be displayed now), and used:

    <?php if(is_category()) { ?>
    <?php } ?>

    for the two second things (the archive and the categories). And it works! So I think I got it right. Do you agree? Thank you for your help ??

    Sounds okay…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to customize the sidebar for pages and categories?’ is closed to new replies.