WordPress.org

Ready to get started?Download WordPress

Forums

New Sidebar for Each Category (13 posts)

  1. pdberger
    Member
    Posted 9 years ago #

    Is it possible to easily create a new sidebar for different categories or pages? I would like to add an About Me section and a Journalism section to my blog, but I would like these sections to have different information in the sidebar than the main page (my blog is at http://www.pdberger.com if it helps). Many thanks to anyone who can help.

  2. moshu
    Member
    Posted 9 years ago #

    If by "pages" you mean the Pages feature in WP - the answer is yes, you can have different sidebar for certain Pages. There might be an easier way, but I'd create a new page-template and a mysidebar.php which would be called only by that template. When it's done write your Pages for that section or whatever using the new template.

    For posts in categories you'd have to wait until a PHP guru comes around and tells you how to go with that... but in the meantime there is a good reading in Codex: Category Templates

  3. Avenir
    Member
    Posted 9 years ago #

    I would do this using if-else PHP statements in the sidebar.php file. In fact, I already do this using if-else statements. I combine them with the is_ functions to test what page is being loaded. So for your situation, you might add this to sidebar.php:

    <?php
    if ( is_page('About Me') ) {
    ?>
    special about me sidebar stuff
    <?php
    }
    elseif ( is_category('Journalism') ) {
    ?>
    special journalism sidebar stuff
    <?php
    }
    ?>

    If you're using the default theme, there is already a whole bunch of if-else statements in the sidebar.php, so you'll have to merge this with those. Find the line:

    <?php /* If this is a category archive */ if (is_category()) { ?>

    and change the if to elseif and delete the <?php. Then paste what I had above in above that line, but leave out the last ?>. That should work.

  4. moshu
    Member
    Posted 9 years ago #

    Yeah... much nicer.
    - probably I should learn some PHP :(

  5. pdberger
    Member
    Posted 9 years ago #

    Sounds like a great solution. Thank you Moshu and Avenir for your help. pdberger

  6. nomad1
    Member
    Posted 8 years ago #

    Is it also possible to display the child categories for a specific category in the way explained above?

    Let's say I have categories English and German. If I'm on the English category page I only want to have the child-categories of the English-category listed plus a specific English menue.

  7. Michael Bishop

    Posted 8 years ago #

    You can also emply the same if...else concept in the page template, and have several completely different sidebars, rather than within the sidebar file. Probably a matter of how different the sidebar's are going to be.

  8. nomad1
    Member
    Posted 8 years ago #

    Thanks, sounds good. As I'm a beginner, how can I make only one specific parent category (and their sub/children categories) to be displayed?

  9. Michael Bishop

    Posted 8 years ago #

    see Avenir's post, but instead of the using ('About Me'), simply use the cat #.

  10. anthonyqkiernan
    Member
    Posted 8 years ago #

    Using the method laid out above I can get my sidebar to change for the parent, but it reverts for children. Any ideas?

  11. Beel
    Member
    Posted 8 years ago #

    I believe as it now is you would have to include the children in the if statement. Might be a nice addition to have an is_page_or_children()

  12. anthonyqkiernan
    Member
    Posted 8 years ago #

    Excuse my ignorance of php syntax. Is there a way to do this in the one line? eg. I'm using
    if ($cat == "4" )
    how do I add other options
    if ($cat in("4", "5")) ? or something

    Or do I need to include the same code for all possible options
    if ($cat == "4" ){?>
    Blah!
    <?php } elseif {($cat == "5" ){?>
    Blah!
    <?php } else {{?>
    Whatever!

  13. moshu
    Member
    Posted 8 years ago #

    The previous posts were about Pages and their children Pages (aka sub-Pages) and Pages do not have categories.
    So, obviously your problem/question is not related because in your code you have "categories".

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.