Forums

different sidebar based off category (13 posts)

  1. thetvstop
    Member
    Posted 3 years ago #

    Hi,

    What I want to accomplish is, I want a different sidebar.php file to be displayed based off the category that is selected. I know I'd have to create a sidebar file for each category, but how do I go about coding it to be displayed based off category?

    I have somewhere around 100 categories that I need to do.

    Thanks,
    Jack

  2. moshu
    Member
    Posted 3 years ago #

    Conditional_Tags - should have all the info you need.

  3. thetvstop
    Member
    Posted 3 years ago #

    hi thanks.

    <?php
    	if (is_category('5') ) {
    		include ('prisonbreakphoto.php');
    	}elseif (is_category('6') ) {
    		include ('ghostwhispererpics.php');
    
    }else{
    	include ('blankpics.php');
    }
    ?>

    Here is my code, but it's not displaying any includes except the blankpics one. I'm in category 5, and it displays the blankpics, not the prisonbreakphoto.php file, how do i fix this?

  4. moshu
    Member
    Posted 3 years ago #

  5. thetvstop
    Member
    Posted 3 years ago #

    thank you.

  6. thetvstop
    Member
    Posted 3 years ago #

    hmm interesting enough. The following code will not display the }else{ statment.

    <?php
    
    if (is_page('2759'|| '2785' || '2788' || '2792') ) {
    
     include(TEMPLATEPATH . '/sidebar/ghostwhispererside.php');
    
    }else{
    
    include(TEMPLATEPATH . '/sidebar.php');
    }
     ?>

    It won't display the sidebar for any other page but the first (ghostwhispererside.php) on every page. any clue what im missing?

  7. iridiax
    Member
    Posted 3 years ago #

    Check with the conditional tags page again, you need to use array with is_page and get rid of the ||.

  8. thetvstop
    Member
    Posted 3 years ago #

    That doesn't work. Which is the reason why || was added. It was working properly but stopped working once I upgraded. Now doing it the way the conditional tags says does not work.

    <?php
    
    if (is_page(array ('2759','2785','2788','2792') ) {
    
     include(TEMPLATEPATH . '/sidebar/ghostwhispererside.php');
    
     }else{
    
    include(TEMPLATEPATH . '/sidebar.php');
    }
     ?>

    Returns the error of:

    Parse error: syntax error, unexpected '{' in /home/camvixsi/public_html/thetvstop/wp-content/themes/thetvstop/pageside.php on line 4

    Line 4 is: if (is_page(array ('2759','2785','2788','2792') ) {

    `

  9. iridiax
    Member
    Posted 3 years ago #

    You need another ) in the following:

    if (is_page(array ('2759','2785','2788','2792') ) {

  10. thetvstop
    Member
    Posted 3 years ago #

    What you posted is exactly what I posted? it returns the same error.

  11. iridiax
    Member
    Posted 3 years ago #

    What you posted is exactly what I posted? it returns the same error.

    Yes, I just reposted your code that needs fixing. All parenthesis must be paired, and yours were not. Here is the fixed bit of code (note the added parenthesis):

    if (is_page(array ('2759','2785','2788','2792'))) {

  12. outshine
    Member
    Posted 2 years ago #

    Is there any way to do this from admin panel.ie. without manual intervention.

    Suppose a blog has more than 100 categories and wants different sidebar for different categories.
    Then is it possible to have widgetized sidebars for each categories from admin panel??
    is there any plugin

  13. MichaelH
    Volunteer
    Posted 2 years ago #

    http://wordpress.org/extend/plugins/widget-logic/ allows you some control over widgets.

Topic Closed

This topic has been closed to new replies.

About this Topic