0

I want an extra sidebar added to this wordpress theme of mine. I want it right under my left sidebar and not next to it as it is currently showing: www.giftforgag.com.

I have tried many things but nothing seems to be working. I have also tried making various changes to the css.

I had thought it would be easiest to simply place get_sidebar('left'); right under the get_sidebar(); function that exists at the very end but it hasn't worked out.

The theme in question is twenty-fourteen and I have placed the code of the file here:

<?php

    get_header(); ?>
    <div id="main-content" class="main-content">

    <?php
        if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
            get_template_part( 'featured-content' );
        }
    ?>

        <div id="primary" class="content-area">
            <div id="content" class="site-content" role="main">
            <?php
                if ( have_posts() ) :
                    while ( have_posts() ) : the_post();

                        get_template_part( 'content', get_post_format() );

                    endwhile;

                    twentyfourteen_paging_nav();

                else :
                    get_template_part( 'content', 'none' );

                endif;
            ?>
            </div><!-- #content -->
        </div><!-- #primary -->
    </div><!-- #main-content -->
    <?php
    get_sidebar();
    get_sidebar('left');
    get_footer();

I have registered the widget using the following code:

function mychild_widgets_init() {
    register_sidebar( array(
        'name'          => __( 'Left Widget Area', 'twentyfourteen' ),
        'id'            => 'sidebar-left',
        'description'   => __( 'Left sidebar.', 'twentyfourteen' ),
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h1 class="widget-title">',
        'after_title'   => '</h1>',
    ) );
}
add_action( 'widgets_init', 'mychild_widgets_init' );

I am also trying this:

'before_wdiget' => '<div id="content">'
'after_widget' => '</div>

Nothing is working so far.

The sidebar.php file is this:

<div id="left">
    <?php if ( is_active_sidebar( 'sidebar-left' ) ) : ?>
    <div id="left-sidebar" class="left-sidebar widget-area" role="complementary">
        <?php dynamic_sidebar( 'sidebar-left' ); ?>
    </div>
    <?php endif; ?>
</div>
3
  • Have you read this? You need to register the sidebar area first: codex.wordpress.org/Widgetizing_Themes
    – kraftner
    Commented Aug 24, 2015 at 9:39
  • This is what I have done to register it: function mychild_widgets_init() { register_sidebar( array('name'=> __( 'Left sidebar', 'twentyfourteen' ), 'id'=> 'sidebar-left', 'description'=> __( 'Left sidebar.', 'twentyfourteen' ), 'before_widget' =>'<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h1 class="widget-title">', 'after_title' => '</h1>', ) ); } add_action( 'widgets_init', 'mychild_widgets_init' ); Commented Aug 24, 2015 at 10:10
  • Please add that to the question and not as a comment.
    – kraftner
    Commented Aug 24, 2015 at 11:06

2 Answers 2

1

get_sidebar('left'); actually refers to a file, not the sidebar itself.

  1. Are you seeing the sidebar in the Admin section?
  2. Are you trying to display it on the front end?

If the answer to both of these questions are "yes", then here's the solution:

Create a file called sidebar-left.php. In this file, you will need to add your rendered HTML, something like this:

<?php
// Left Sidebar template
?>
<div id="left-sidebar" class="sidebar">
    <?php dynamic_sidebar( 'sidebar-left' ); ?>
</div>
5
  • Thanks Eric, my sidebar.php file has already been created. I have added the code in the question. So you can see. Commented Aug 24, 2015 at 13:29
  • Well, your sidebar appears to be showing up. When I view source of the page, I found <div id="left-sidebar" class="left-sidebar widget-area" role="complementary"> Commented Aug 24, 2015 at 13:51
  • You just need to add Widgets to it in the Admin area to have them start showing up. It may be empty right now Commented Aug 24, 2015 at 13:52
  • Yes it is. But I want it just below the primary sidebar. Not after the content as it is showing right now. I want a sidebar right below the main left sidebar. Commented Aug 24, 2015 at 13:52
  • Then use CSS. It's your decision where you place the <?php get_sidebar( 'left' ) ?> declaration. You'll also need to apply either the same CSS classes to the containers, or write some CSS... This is solved. Commented Aug 24, 2015 at 14:14
0

You are mixing up a couple of things here, namely

register_sidebar()

This is to register a sidebar so you can put stuff into it in the backend.

get_sidebar()

This just includes a file sidebar.php (or sidebar-nice-bar.php if you call get_sidebar('nice-bar')) from your current theme

dynamic_sidebar()

This actually displays the widgets you have added in the backend to the sidebar area defined with register_sidebar. This is probably done in one of the files referenced in get_sidebar.

So what you need to do based on your question is either replacing

get_sidebar('left');

with

dynamic_sidebar('left');

or create a file called sidebar-left.php in your theme and add dynamic_sidebar('left') to it.

For a more detailed, excellent explanation have a look at this excellent post by @justin-tadlock

2
  • I already have dynamic_sidebar written in my sidebar-left.php file. I think this is more of a problem of placement. I am unable to place it correctly or maybe I need to do something with the css. Commented Aug 24, 2015 at 13:51
  • Oh sorry I somehow didn't read the first line properly and didn't see that it is there but wrongly placed. This is a purely CSS issue then which unfortunately is off-topic here. Try stackoverflow.com
    – kraftner
    Commented Aug 24, 2015 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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