• wpress2010

    (@wpress2010)


    There’s a lot of semi-ambiguous info out there on how to do this.

    I successfully edited my child theme’s functions.php, sidebar.php and header.php files, and when I go to the Widgets panel, indeed my new sidebar is there. I can add widgets to it.

    I still don’t see the new sidebar on the pages. I suspect it is because I haven’t added the following line of code (my sidebar is named ‘sidebar-2’):

    <?php get_sidebar(‘2’); ?>

    to what are referred to as “Theme files” in various posts around here. In WHAT files, exactly, do I need to add this code? I tried to see where in the Theme files the original sidebar was being called, but that didn’t help.

    Sorry if this is a stupid question, but no one actually comes out and gives an example of WHAT files in which to place this code to enable the new sidebar. I want the new sidebar to appear on every site page.

    TIA!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Madhusudan Pokharel

    (@madhusudan977)

    Thread Starter wpress2010

    (@wpress2010)

    Thanks, but in that entire thread (fairly old, by now…) the last part of the solution involves calling the new sidebar in the theme’s index.php file. Twenty Fifteen’s index.php calls no sidebars at all:

    <?php
    /**
    * The main template file
    *
    * This is the most generic template file in a WordPress theme
    * and one of the two required files for a theme (the other being style.css).
    * It is used to display a page when nothing more specific matches a query.
    * e.g., it puts together the home page when no home.php file exists.
    *
    * Learn more: {@link https://codex.www.ads-software.com/Template_Hierarchy}
    *
    * @package WordPress
    * @subpackage Twenty_Fifteen
    * @since Twenty Fifteen 1.0
    */

    get_header(); ?>

    <div id=”primary” class=”content-area”>
    <main id=”main” class=”site-main” role=”main”>

    <?php if ( have_posts() ) : ?>

    <?php if ( is_home() && ! is_front_page() ) : ?>
    <header>
    <h1 class=”page-title screen-reader-text”><?php single_post_title(); ?></h1>
    </header>
    <?php endif; ?>

    <?php
    // Start the loop.
    while ( have_posts() ) : the_post();

    /*
    * Include the Post-Format-specific template for the content.
    * If you want to override this in a child theme, then include a file
    * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    */
    get_template_part( ‘content’, get_post_format() );

    // End the loop.
    endwhile;

    // Previous/next page navigation.
    the_posts_pagination( array(
    ‘prev_text’ => __( ‘Previous page’, ‘twentyfifteen’ ),
    ‘next_text’ => __( ‘Next page’, ‘twentyfifteen’ ),
    ‘before_page_number’ => ‘<span class=”meta-nav screen-reader-text”>’ . __( ‘Page’, ‘twentyfifteen’ ) . ‘ </span>’,
    ) );

    // If no content, include the “No posts found” template.
    else :
    get_template_part( ‘content’, ‘none’ );

    endif;
    ?>

    </main><!– .site-main –>
    </div><!– .content-area –>

    <?php get_footer(); ?>
    I think the problem is in header.php. I am still working on this, as it also involves modifying the Bootstrap-based structure to alloe for the new sidebar’s column, which is, at least in this theme, enabled in a non-intuitive manner, IMHO.

    stephencottontail

    (@stephencottontail)

    When you call get_sidebar( '2' );, WordPress tries to load a file named sidebar-2.php. If you want to call another registered sidebar, you need to call dynamic_sidebar( 'sidebar-2' ).

    As for where you’d place the code, it depends on where you’d like the new sidebar to appear. If you want the sidebar to appear in the content area on all pages, you’ll probably want to place it in index.php, archive.php, single.php, and page.php. You’ll also probably want to give it it’s own containing element:

    <?php if ( is_active_sidebar( 'sidebar-2' ) // this line checks whether there are widgets assigned to the sidebar : ?>
      <div class="sidebar-2">
        <?php dynamic_sidebar( 'sidebar-2' ); ?>
      </div>
    <?php endif; ?>
    Thread Starter wpress2010

    (@wpress2010)

    That’s very helpful, thanks.

    I’ve got it all working, more or less. Now, I have to wade thorugh the CSS to make it all add up ion different platofrms. The use of before :: and after :: in the code make it a bit more time consuiming to figure out, as trying immediate percentile changes to the existing widths of these elements…

    div.sidebar
    div.sidebar-2
    div#primary.content-area

    …does not produce the intended results for a three-column layout.
    It’s all in the CSS, but will require a bit of fiddling to get right.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Twenty Fifteen: Add additional sidebar’ is closed to new replies.