• I am using a theme and want the sidebar to be different for a particular category , so rather than have 2 sidebar files , ie sidebar.php and sidebar2.php , i tried to use the “is_category(‘catname’)” function within the sidebar.php file

    However I cannot get it to work even whan i put some simple code in it just doesnt seem to run, any ideas

    I put the following code in the sidebar.php as a test

    <?php if(is_category(‘blog’)) { echo “sss”; } ?>

    it just doesnt work but if i put this code in Archive.php, it does work…

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Are you using sidebar widgets, perhaps?

    Thread Starter neowp

    (@neowp)

    errrm Yes I am ?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Well, sidebar widgets tend to REPLACE all the code in the sidebar.php file with their own code. So nothing you put in the sidebar.php shows up.

    Look at the call to the dynamic_sidebar function. Notice how if it succeeds then nothing in the sidebar.php is actually executed.

    Thread Starter neowp

    (@neowp)

    thats cool but im trying to something like this in sidebar.php

    if (is_category('blog') { ?>
    <div id="sidebar-top">
    <?php 	/* Widgetized sidebar, if you have the plugin installed. */ 					if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(1) ) : ?>
    <?php endif; ?>
    </div>
    
    </div>
    
    <div id="sidebar-bottom">
    <?php 	/* Widgetized sidebar, if you have the plugin installed. */ 					if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(4) ) : ?>
    <h3><?php _e('Tag Cloud','arthemia');?></h3>
    <?php wp_tag_cloud(''); ?>
    <?php endif; ?> </div>   
    
    </div>
    
    <? }?>

    so i want those widgets to only show on the blog page

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Do you have a blog category? Are you on the /category/blog page when this runs?

    Thread Starter neowp

    (@neowp)

    Yes and Yes, basically I am using this same code ie the

    if (is_category(‘blog’)) {

    do this

    }

    else {

    do that

    }

    on other pages , archives.php etc but I just cant get it to work in sidebar.php, i thought it maybe something to do with the scope of where is_category function is usable , but then it’s PHP and sidebar is just an include surely it should be usable ?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    No, is_category is usable anywhere.

    Are you doing a manual query_posts() call somewhere? This can alter the result of the is_whatever() values.

    It’s a bit of a hack, but when I couldn’t get the ‘cat’ to come over to my sidebar, I resorted to ($_GET[‘cat’]) in the sidebar to dynamically change portions of the sidebar depending on the category being called.

    I had a lot of query_posts and rewinds in my category pages…

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘is_category in Sidebar.php’ is closed to new replies.