treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Wordpress...no sidebars...'sidebar' for each post?

  • I want to put together a Wordpress theme where I don't use the traditional sidebar but rather give each post it's own 'sidebar' where I put links related to that particular post. Anyone know how to do this? Has it been done elsewhere?
  • A quick google search for 'related posts widget' should sort you out. Here's one...

    http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/

    You'll need to create an extra sidebar module to use the widget only in single.php. Here's the easy way....

    Add this to your functions.php file.

    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'related',
    'before_widget' => '<li id=\"%1$s\" class=\"widget %2$s\">',
    'after_widget' => '</li>',
    'before_title' => '<h2 class=\"widgettitle\">',
    'after_title' => '</h2>',
    ));


    then add this to single.php where you want the widget to appear.

    <ul>
    <?php if ( !function_exists('dynamic_sidebar')
    || !dynamic_sidebar('related') ) : ?>
    <?php endif; ?>
    </ul>


    Choose 'related' from the drop down menu in Themes->Appearance->Widgets and add the 'related posts' widget to that sidebar module.

    Sorted!