0

The sidebar I'm using uses an if else statement. No matter what I do it always displays the else default sidebar. They seem to be registered, as they show up in the admin widgets section. I can can add widgets to them, but they do not show up in the page. Only the default sidebar.

This is the sidebar template

<aside id="sidebar" role="complementary">
            <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
                <div class="widget">
                    <h3>Search</h3>
                    <?php get_search_form(); ?>
                </div>

                <div class="widget">
                    <h3 class="wtitle">Categories</h3>
                    <ul>
                        <?php wp_list_categories('title_li='); ?>
                    </ul>
                </div>

                <div class="widget">
                    <h3 class="title">Archives</h3>
                    <ul>
                        <?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
                    </ul>
                </div>

                <div class="widget">
                    <h3 class="title">Meta</h3>
                    <ul>
                        <?php wp_register(); ?>
                        <li><?php wp_loginout(); ?></li>
                        <?php wp_meta(); ?>
                    </ul>
                </div>
            <?php endif; ?>
            </aside>

this is what calls it

   <?php get_header(); ?>
<div id="content" class="wrapper">
    <?php get_sidebar(); ?>
    <div id="main">
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <article id="post-<?php the_ID(); ?>" class="post postbrdr" role="article">
            <header class="posthead">
                <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                <span class="meta">
<i>Published <time datetime="<?php echo the_time('Y-m-j'); ?>"><?php echo the_time(get_option('date_format')); ?></time> by <?php the_author_posts_link(); ?>.</i>
<i>Filed under <a href="#" rel="category"><?php the_category(', '); ?></a>. Total of <a href="<?php comments_link(); ?> "><?php comments_number( 'no comments', '1 comment', '% comments' ); ?></a> in the discussion.<?php edit_post_link('Admin Edit', ' ', '.'); ?></i>
</span>
            </header>
            <section class="post-content clearfix">
                <?php the_content(); ?>
            </section>
        </article>
        <?php endwhile; ?>
        <div id="navbelow" class="clearfix">
            <div class="nav-prev">
                <?php previous_posts_link( "&laquo; Older Entries"); ?>
            </div>
            <div class="nav-next">
                <?php next_posts_link( "Newer Entries &raquo;"); ?>
            </div>
        </div>
        <?php else : ?>
        <article id="post-not-found" class="post">
            <header class="posthead">
                <h2>Whoops! Looks like we can't find this post.</h2>
            </header>

            <section class="post-content">
                <p>It seems like this post is missing somewhere. Double-check the URL or try navigating back via the website menu links.</p>
            </section>
        </article>
        <?php endif; ?>
    </div>
    <!-- /#main -->
</div>
<!-- /#content -->
<br style="clear:both;">

<?php get_sidebar( 'responsive' ); ?>
<?php get_footer(); ?>

and here is responsive.php

<aside id="sidebar-responsive" class="wrapper" role="complementary">
        <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) : else : ?>
        <div class="widget">
<h3 class="wtitle">Blog Categories</h3>
<ul>
<?php wp_list_categories('title_li='); ?>
</ul>
</div>
<div class="widget">
<h3 class="title">Post Archives</h3>
<ul>
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
</ul>
</div>      
        <?php endif; ?>
        </aside> <!-- /#sidebar-responsive -->>

and this is the registration

* Setting up custom sidebars
 *
 */
if(function_exists('register_sidebar')) {
    register_sidebar(array(
        'name' => 'Main Sidebar',
        'id' => 'main',
        'before_widget' => '<div class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<h3 class="wtitle">',
        'after_title' => '</h3>'
    ));

    register_sidebar(array(
        'name' => 'Responsive Sidebar',
        'id' => 'responsive',
        'before_widget' => '<div class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<h3 class="wtitle">',
        'after_title' => '</h3>'
    ));
2

Your sidebars will not work the way you are calling them. <?php get_sidebar(); ?> calls the template sidebar.php, while <?php get_sidebar( 'responsive' ); ?> calls the template sidebar-responsive.php

To call your two sidebars in a template, you will need to use dynamic_sidebar() to call them as per example

<?php if ( is_active_sidebar( 'responsive' ) ) : ?>

   <?php dynamic_sidebar( 'responsive' ); ?>

<?php endif; ?>

EDIT

Ok, there are a few mistakes here.

First, what I believe is your sidebar.php template, you have this code

 <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>

You don't make a call to any specific sidebar. You need to specify a sidebar to use, so you need to change that line to

 <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar( 'main' ) ) : ?>

if you want to use sidebar with id main.

Secondly, you are calling a sidebar template that does not exist. As stated, <?php get_sidebar( 'responsive' ); ?> calls sidebar-responsive.php, which does not exist. You will need to change responsive.php to sidebar-responsive.php to work properly.

Thirdly, this line is also wrong

<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) : else : ?>

You are calling a sidebar with id of '2', which according to what you've registered doesn't exist. I believe this should actually be 'responsive' if I have a look at the template name. You can also just use the the same structure as in sidebar.php to call the sidebar like this

 <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar( 'responsive' ) ) : ?>

Hope this is what you need.

5
  • Thanks for the response, but it is still calling the default sidebar
    – Greg
    May 21 '14 at 18:47
  • Please post all relevant code. Your code your posted doesn't show any of the sidebars been called, nor does it shows the conditional statement you are talking about. The code you've posted, from which file is that May 21 '14 at 18:50
  • What code do you use in sidebar-responsive.php? May 21 '14 at 19:02
  • Apologies. I've added responisve.php above
    – Greg
    May 21 '14 at 19:13
  • Updated answer. Check if it works. Off to bed now unfortunately so I can only give more assistance tommorrow again. Go and have a look also at how the default themes register and use their sidebars. I really hope you get your problem solved. Also go and check out the link I provided May 21 '14 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.