• Dear WP Gods,

    After a forum search and reading a handful of posts I still cannot figure out this problem, I greatly appreciate your help.

    https://www.elanabell.com is a site I made for a client of mine. It uses the TwentyEleven theme edited with a child theme. All pages are single column. Now my client would, understandably, like some organization for her blog. This means adding a sidebar to the blog page, for which I’m using the ‘page of posts’ template.

    I discovered the <?php get_sidebar(); ?> command but when I add it to page_of_posts.php in my childtheme, nothing happens.

    At one point I added the HTML for two widgets (which showed up and worked) but I was having difficulty with making them look nice, plus, I feel like this was the wrong approach as I would like to use WP’s widget panel.

    I was reading this article by Alchymyth: https://www.transformationpowertools.com/wordpress/twenty-eleven-sidebar-on-single-posts-and-pages

    But I got confused with the filter bit.

    I would also like this sidebar to show up on the individual article pages.

    Can someone please help me add this sidebar to the blog and article pages so I can edit it using WP’s built-in widget panel?

    Thanks heaps,
    Ross

Viewing 12 replies - 1 through 12 (of 12 total)
  • for a new page template with sidebar in a child theme of Twenty Eleven, you are better of reading this article: https://www.transformationpowertools.com/wordpress/twenty-eleven-new-page-template-with-sidebar-correction

    make sure your sidebar call is at the same position as in sidebar-page.php

    Thread Starter rconnard

    (@rconnard)

    I added the following code in functions.php right after <?php

    add_filter('body_class', 'adjust_body_class', 20, 2);
    function adjust_body_class($wp_classes, $extra_classes) { 
    
    if( is_page_template('blog.php') ) :
    // Filter the body classes     
    
          foreach($wp_classes as $key => $value) {
          if ($value == 'singular') unset($wp_classes[$key]);
          }
    
    endif;
    // Add the extra classes back untouched
    return array_merge($wp_classes, (array) $extra_classes );
    }

    What do you mean by in the same position as sidebar-page.php?

    the function code only helps with the formatting;

    if you haven’t already, you still need to add
    <?php get_sidebar(); ?>
    into blog.php, just before the ‘get_footer’ line.

    Thread Starter rconnard

    (@rconnard)

    I have… here is what the end of blog.php looks like

    <div class="entry-content">
    <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
    <?php get_search_form(); ?>
    </div>
    </article>
    
    <?php endif; ?>
    
    </div>
    </div>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    are you sure that this template is used in the live site?

    there is no trace of any sidebar in the html code of the ‘blog’ page of your site.

    check the code of blog.php in your site by going to dashboard – appearance – editor – make sure Twentyeleven Child is selected as theme, and select blog.php

    Thread Starter rconnard

    (@rconnard)

    Dashboard-appearance-editor is where I copied this code from.

    <?php
    /*
    Template Name: Page Of Posts
    */
    
    // if you are not using this in a child of Twenty Eleven, you need to replicate the html structure of your own theme.
    
    get_header(); ?>
    <div id="primary">
    <div id="content" role="main">
    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'category_name' => 'newsletter,uncategorized', // Change these category SLUGS to suit your use.
    	'paged' => $paged
    );
    query_posts($args);
    if( have_posts() ) :?>
    
    <?php twentyeleven_content_nav( 'nav-above' );?>
    
    <?php while ( have_posts() ) : the_post(); ?>
    
    <?php get_template_part( 'content', get_post_format() ); ?>
    
    <?php endwhile; ?>
    
    <?php twentyeleven_content_nav( 'nav-below' ); ?>
    
    <?php else : ?>
    <article id="post-0" class="post no-results not-found">
    <header class="entry-header">
    <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
    </header><!-- .entry-header -->
    
    <div class="entry-content">
    <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
    <?php get_search_form(); ?>
    </div>
    </article>
    
    <?php endif; ?>
    
    </div>
    </div>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    That’s the full code from the page. Perhaps something is messed up? I don’t understand PHP much so it’s difficult for me to tell.

    This is also where I added the widgets with HTML and they showed up, so I know this document is working.

    Thread Starter rconnard

    (@rconnard)

    Is there any other information I can give you that would help figure this out?

    is the page template used for the ‘blog’ page ‘Page Of Posts’ ?

    have you edited sidebar.php at all?
    if yes, what is the code of sidebar.php?

    Thread Starter rconnard

    (@rconnard)

    I’m not sure if page.php is used for page of posts. Under ‘Pages’ I assigned the blog page the template of ‘page of posts’.

    I do not think I have edited sidebar.php but here is the code:

    <?php
    /**
     * The Sidebar containing the main widget area.
     *
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0
     */
    
    $options = twentyeleven_get_theme_options();
    $current_layout = $options['theme_layout'];
    
    if ( 'content' != $current_layout ) :
    ?>
    		<div id="secondary" class="widget-area" role="complementary">
    			<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
    
    				<aside id="archives" class="widget">
    					<h3 class="widget-title"><?php _e( 'Archives', 'twentyeleven' ); ?></h3>
    					<ul>
    						<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
    					</ul>
    				</aside>
    
    				<aside id="meta" class="widget">
    					<h3 class="widget-title"><?php _e( 'Meta', 'twentyeleven' ); ?></h3>
    					<ul>
    						<?php wp_register(); ?>
    						<li><?php wp_loginout(); ?></li>
    						<?php wp_meta(); ?>
    					</ul>
    				</aside>
    
    			<?php endif; // end sidebar widget area ?>
    		</div><!-- #secondary .widget-area -->
    <?php endif; ?>

    are you using the ‘one-column’ layout theme option?

    this line – if ( 'content' != $current_layout ) : – only proceeds with showing the sidebar if one of the ‘content on left’ or ‘content on right’ options is selected.

    my mistake – forgot about that code, and I should have seen that earlier from the body classes in your site.

    -the following is very specialized and applies only to the site under discussion-

    to show a sidebar in a page template despite the ‘one-column’ option;
    for a page template saved as blog.php

    you need to edit sidebar.php in your child theme:
    change the conditional line near the top of the template to:

    if ( 'content' != $current_layout || is_page_template('blog.php') ) :

    edit functions.php and change the filter for the correction of the body_class to:

    add_filter('body_class', 'adjust_body_class', 20, 2);
    function adjust_body_class($wp_classes, $extra_classes) { 
    
    if( is_page_template('blog.php') ) :
      // correction for the Sidebar Template 'right sidebar on page in one-column layout'
        $classes[] = 'right-sidebar';
        $classes[] = 'two-column';
        $blacklist = array('one-column','content','left-sidebar','singular');
        // Filter the body classes
        foreach( $blacklist as $val ) {
          if (!in_array($val, $wp_classes)) : continue;
          else:
          foreach($wp_classes as $key => $value) {
            if ($value == $val) unset($wp_classes[$key]);
          }
          endif;
        }
      endif;
    // Add the extra classes back untouched
    return array_merge($wp_classes, (array) $extra_classes );
    }

    and to keep the same width, edit style.css in the child theme, and add:

    .page-template-blog-php #page { max-width: 735px; }

    that should in principle work; however, there will be much more adjustments needed for the formatting; partly to compensate the effects of the ‘responsive styles’ when you narrow the browser screen or view the site on a tablet or smart phone.

    Thread Starter rconnard

    (@rconnard)

    Alchemyth,

    I really appreciate your help. I would be lost in a sea of code without you.

    I’ve made these adjustments as you instructed and it looks like there is space for a sidebar but I do not see any widgets there. I’m not sure if this is the ‘main sidebar’ or the ‘showcase sidebar’ but I have one widget in each and see neither on the blog page.

    Also the background image on this page has now disappeared.

    https://www.elanabell.com/blog

    Thanks again,
    Ross

    did you do these three steps:

    – edit sidebar.php in your child theme;
    change the conditional line near the top of the template …

    – edit functions.php in your child theme and change the filter for the correction of the body_class …

    – edit style.css in the child theme, and add …

    (you obviously have edited the style.css, however, possibly try to move these lines:

    /*BLOG PAGE*/
    .page-template-blog-php #page { max-width: 735px; }

    to before the @media styles)

    please post (pastebin) the latest versions of those templates in the child theme:

    – sidebar.php
    – functions.php
    – blog.php

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Adding Sidebar to Blog Page’ is closed to new replies.