Support » Fixing WordPress » can single posts be coded to call sidebars specific to individual post

  • I use many custom sidebars throughout my blog. I understand how to make different categories call and display sidebars specific to them. for example, a category called “surf” calls a “surf sidebar” with surf report information.

    however, when a post that appears in the surf category is viewed as a single post, it displays the sidebars specified by the generic single post template.

    I would like to be able to add a custom key or something to individual posts as i write them that specifies which sidebars will appear with the post when it appears in single post form (like having a single post on surfing display the “surf sidebar” my surf category template specifies and calls).

    I hope this is clear. Thanks much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You could change the get_sidebar call in your single.php with something like

    <?php
    if (in_category('2'))
    include (TEMPLATEPATH . '/sidebar2.php');
    elseif (in_category('3'))
    include (TEMPLATEPATH . '/sidebar3.php');
    elseif (in_category('4'))
    include (TEMPLATEPATH . '/sidebar4.php');
    else get_sidebar();
    ?>
    Thread Starter thebradmiskell

    (@thebradmiskell)

    thank you, moshu. again, you’ve been a big help. your suggestion works perfectly.

    however, in some instances, i’d like the include statements to call multiple sidebars. i’ve experimented (guessed, more like it) with syntax such as:

    <?php
    if (in_category(‘2’))
    include (TEMPLATEPATH . ‘/sidebar2.php’&’/sidebar22.php’);

    and

    <?php
    if (in_category(‘2’))
    include (TEMPLATEPATH . ‘/sidebar2.php’);(TEMPLATEPATH . ‘/sidebar22.php’);

    which might make you laugh.

    and I’ve looked at tutorials so that I didn’t have to ask you. But I’m working with a theme that uses the following method to call sidebars:

    <?php include(TEMPLATEPATH.”/sidebar4.php”);?>

    <?php include(TEMPLATEPATH.”/sidebar3.php”);?>

    and i can’t figure out, with the open, if/elseif statement, how to call multiple sidebars in the way that the above, consecutive statements do.

    thanks, again, for your help and consideration.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘can single posts be coded to call sidebars specific to individual post’ is closed to new replies.