display different sidebar depending on which category you select. (5 posts)

  1. 2helix
    Posted 8 years ago #

    I ma not a php guy, but I have been trying to get this to work with no luck. I have created a different sidebar for the baseball category and I have edited my category.php to try and make the baseball sidebar appear when the baseball category is selected. Here is the category code I have been trying to get working

    <?php get_header(); ?>
    <?php if ( in_category('26') ) { ?>
    <?php include ('pagesidebar_baseball.php'); ?>
    <?php } else { ?>
    <?php get_sidebar(); ?>

    <div class="middle">

    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <div id="post-<?php the_ID(); ?>">
    <h2>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h2>
    <p><small><?php the_time('F jS, Y') ?> <?php the_author() ?></small> Posted in <?php the_category(', ') ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', '', ' | '); ?> <?php if(function_exists('the_views')) { the_views(); } ?></p>

    <div class="entry">
    <?php the_content('Read the rest of this entry »'); ?>
    <!-- AddThis Bookmark Post Button BEGIN -->
    <?php echo "<div class=\"addthis\"><img src=\"http://s9.addthis.com/button1-bm.gif\" width=\"125\" height=\"16\" border=\"0\" alt=\"AddThis Social Bookmark Button\" /></div>"; ?>
    <!-- AddThis Bookmark Post Button END -->

    <div class="br">
    <?php endwhile; ?>

    <div class="alignleft"><?php next_posts_link('« Previous Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Next Entries »') ?></div>

    <?php else : ?>

    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>


    <?php get_sidebar(); ?>

    <?php get_footer(); ?>

    I am doing something wrong and I am very confused.
    Can a php master please step in and point me in the right direction?

  2. moshu
    Posted 8 years ago #

  3. 2helix
    Posted 8 years ago #

    Thanks Moshu :)

  4. 2helix
    Posted 8 years ago #

    I still cant get it right. I now have 2 sidebars ..lol
    This is what I have at the top of my category.php file, maybe you can give me some help?

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
    } elseif (is_category(26)) {
    <?php include ('rsidebar_baseball.php'); ?>

    I suck at this.

  5. moshu
    Posted 8 years ago #

    Well, I am not a coder but even I can tell that code will never work.
    Take a look at the examples on the codex page I've linked to above:

Topic Closed

This topic has been closed to new replies.

About this Topic