2

I have a child theme based on Twenty Ten.

I have split out the sidebar and secondary side bar so they can be used on different pages.

sidebar.php file:

<div id="primary" class="widget-area" role="complementary">
    <ul class="xoxo">

    <?php
    /* When we call the dynamic_sidebar() function, it'll spit out
     * the widgets for that widget area. If it instead returns false,
     * then the sidebar simply doesn't exist, so we'll hard-code in
     * some default sidebar stuff just in case.
     */
    if ( ! dynamic_sidebar( 'primary-widget-area' ) ) : ?>

        <li id="search" class="widget-container widget_search">
            <?php get_search_form(); ?>
        </li>

        <li id="archives" class="widget-container">
            <h3 class="widget-title"><?php _e( 'Archives', 'twentyten' ); ?></h3>
            <ul>
                <?php wp_get_archives( 'type=monthly' ); ?>
            </ul>
        </li>

        <li id="meta" class="widget-container">
            <h3 class="widget-title"><?php _e( 'Meta', 'twentyten' ); ?></h3>
            <ul>
                <?php wp_register(); ?>
                <li><?php wp_loginout(); ?></li>
                <?php wp_meta(); ?>
            </ul>
        </li>

    <?php endif; // end primary widget area ?>
        </ul>
    </div><!-- #primary .widget-area -->

sidebar-2.php

    <?php
    // A second sidebar for widgets, just because.
    if ( ! dynamic_sidebar( 'secondary-widget-area' ) ) : ?>

        <div id="secondary" class="widget-area" role="complementary">
            <ul class="xoxo">
                <?php dynamic_sidebar( 'secondary-widget-area' ); ?>
            </ul>
        </div><!-- #secondary .widget-area -->
<?php endif; ?>

I want to display sidebar-2 (the secondary sidebar) in my post pages. I call them using:

<?php get_template_part(‘sidebar’,2); ?>

(in the following files: archive.php, post.php, author.php, category.php)

instead of <?php get_sidebar(); ?>

I've set my 'Settings' for 'Reading' so that the page is for displaying 'Posts'.

When I visit the page, it displays the primary sidebar. You can see for yourself at http://akhomehealth.com/newsletter/

Sidebar should show search, archive, category and recent posts.

1
  • So I discovered that Wordpress 3.1 twenty-Ten is using the home.php as the template for posting page. Now I'd like to ask WP why? However, I really need to get it to show the secondary sidebar.
    – Nohl
    Commented Mar 15, 2011 at 1:33

2 Answers 2

3

try this instead <?php get_sidebar(2); ?>

3
  • That was a cool suggestion, however it did not use the newly created sidebar-2.php (as far as I can tell) and it did not let me correctly tell WP 3.1 that I want to use a different template for my blog page. Still that was a cool suggestion.
    – Nohl
    Commented Mar 11, 2011 at 5:43
  • 2
    Try casting the 2 as a string instead, eg. get_sidebar('2');..
    – t31os
    Commented Mar 11, 2011 at 12:37
  • turns out the '2' is the big deal when using <?php get_sidebar(2); ?> @t31os was right about casting (just noticed that short tip) - if you don't put it in single quotes the function gets really confused. I guess I miss read it. . I still had to make many changes to the sidebar.php and sidebar-2.php, but I get it now. . I don't get why Twenty-Ten uses the home.php template for internal blog/post pages. Any ideas?
    – Nohl
    Commented Mar 16, 2011 at 6:02
1

This is the wrong usage of using get_template_part as below:

<?php get_template_part(‘sidebar’,2); ?>

This is the correct one. (Since the file name was sidebar-2.php.)

<?php get_template_part('sidebar','2'); ?>

This also the correct one. (More direct approach)

<?php get_template_part('sidebar-2'); ?>

I noticed that you type the symbol of ‘ and ’ inside the code ‘sidebar’. It should be 'sidebar'. Or else it may not working. You should aware the symbol on your keyboard

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.