WordPress.org

Ready to get started?Download WordPress

Forums

different sidebar on post pages dependent on category (6 posts)

  1. joeby
    Member
    Posted 6 years ago #

    My WP has multiple authors, multiple categories. I'm using a 3 column design and want to have left and right columns pull up different text / widgets for topic specific advertising instead of having the same sidebars show for everything.

    I'm not talking about pages created where I can pick a template (write -> pages).

    For the purpose of being specific, an example:

    Drums
    - Instructional
    - Tips
    - Product reviews

    Video Games
    - System 1
    - System 2

    Books
    - Genre 1
    - Genre 2

    Keeping in mind that these are post pages and categories, I'd like to have specific content in the sidebars of each page in a given category so that people reading about Video Games and interested in a specific game brand would see ads relevant to that system. While people interested in books would see no ads for games, but instead ads for books...

    To complicate things further, the site starts on a landing page on which I'd like to have control of the sidebars as well...

    Is there an easy way to do this? Or a widget somewhere that would do it?

    Thanks,
    Joeby

  2. York
    Member
    Posted 6 years ago #

    I would like to achieve a similar goal with my website, but I haven't found a forum discussion that clearly explains how.

    If someone knows how, or can point to a resolved discussion on the topic, I'd appreciate it.

    Cheers,

    York

  3. dalei
    Member
    Posted 5 years ago #

    I am also looking for a solution that allows me to have different sidebar php files for different pages like home, post and archives.

    I see in WordPress Admin in the Design Widgets page, you can select a sidebar from a pull down, HOW do I add sidebars into that pull down so I can specify different widgets to each one..
    ???anyone

  4. bdayne
    Member
    Posted 5 years ago #

    This requires a two step process. First, you need to add a sidebar, or more, as needed to your functions.php template. This will add further selections to the drop-down menu of the widgets page. You can format these new sidebars just as you would any other wigetized sidebar.

    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'Your Memorable Sidebar Name',
    'before_widget' => '<div class="sidebar_widget">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
    ));

    Then, in your single.php or page.php template, replace the code that calls the standard sidebar:
    <?php get_sidebar(); ?>

    Using conditional tags you can then call the newly created sidebars according to whatever conditions you like. For instance, I have created different sidebars to place ads according post category on my single post pages. The conditional tags say "check the category number and if it's x, load sidebar a." While my example uses is_category, it could just as easily use is_page, and specify a page number. Using this code allows you to create as many different sidebars as a you like, and apply the same widgets to multiple sidebars.

    <?php
    if (is_category(3))
        {if( function_exists('dynamic_sidebar') && dynamic_sidebar(Podcast Sidebar) ) ;
        }
    elseif (is_category(30))
        {if( function_exists('dynamic_sidebar') && dynamic_sidebar(Reviews Sidebar) ) ;
        }
    elseif (is_category(34))
        {if( function_exists('dynamic_sidebar') && dynamic_sidebar(Articles Sidebar) ) ;
        }
    elseif (is_category(37))
        {if( function_exists('dynamic_sidebar') && dynamic_sidebar(Found Objects Sidebar) ) ;
        }
        else
        {if( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ) ; else ;} ?>
  5. staygoldstudio
    Member
    Posted 5 years ago #

    Hi there Bdayne,
    Your reply is very helpful, though when doing the exact same steps as you described above, i'm getting this error:

    "Warning: Cannot modify header information - headers already sent by (output started at /data/members/paid/r/o/rotterdamfixedgear.com/htdocs/www/site/wp-content/themes/stripedflowers/functions.php:6) in /data/members/paid/r/o/rotterdamfixedgear.com/htdocs/www/site/wp-includes/pluggable.php on line 770"

    Do you happen to have any idea why this is?

    Kind regards,
    Roy

  6. iridiax
    Member
    Posted 5 years ago #

    Warning: Cannot modify header information - headers already sent by...

    See this: Headers already sent

Topic Closed

This topic has been closed to new replies.

About this Topic