Forums

[resolved] Sidebar logic for post/blogroll and page type (4 posts)

  1. proximity2008
    Member
    Posted 2 years ago #

    I've spent all night trying to solve this and it is driving me mad.

    I have 2 sidebars setup. Sidebar1 is used throughout the site on only static pages. The other is to be used on post pages and the blogroll page, where all posts are shown. Here is the code that I've got in sidebar.php:

    <?php if(is_singular($post)): ?>
    	<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ): endif; ?>
    <?php else:?>
    	<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) : endif; ?>
    <?php endif;?>

    This nearly works on the blog roll page, but when you click into a post the logic fails and sidebar 1 is called instead of sidebar 2.
    Here is what I want:

    if: this page is a static page then show sidebar1
    elseif: this is post content type -  show sidebar2
    else: this is a blogroll show sidebar2

    I've looked at slayer's widget plugin and widget logic and could not get them to work on the blogroll pages (ie not widget's were shown). Other people have been asking for the fixes to these bugs - nothing yet.

    This is frustrating, surely someone has done something similar please help!

  2. alanft
    Member
    Posted 2 years ago #

    you should trawl through some more conditional tags

    http://codex.wordpress.org/Conditional_Tags

    to find what you need

  3. proximity2008
    Member
    Posted 2 years ago #

    There is a is_front_page function which would work if the blog posts were on the homepage. But my case it is on another page.

    There is no "is this page I'm viewing the posts landing page".

    <?php if(is_page()): ?>
    	<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ):?><?php endif; ?>
    <?php elseif (is_single() || is_this_the_blog_landing_page): ?>
    	<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) :?><?php endif; ?>
    <?php endif;?>
  4. proximity2008
    Member
    Posted 2 years ago #

    <?php if(is_page()): ?>
    	<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ):?><?php endif; ?>
    <?php elseif (is_single() || is_home()): ?>
    	<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) :?><?php endif; ?>
    <?php endif;?>

    is_home is the one that I wanted.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags