Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My site has the following structure where one column is for the main content (articles) and the other one, on the right, is for the sidebar (primary sidebar).

The theme allows me to change the layout to three-col, however it's a "side-wide" change. I don't want three columns on main content section.

Is there a way to show this second sidebar only on category pages?

Here is the code for the secondary sidebar:

<?php
/**
 * Alternate Sidebar Template
 *
 * If a `secondary` widget area is active and has widgets,
 * and the selected layout has a third column, display the sidebar.
 *
 * @package WooFramework
 * @subpackage Template
 */
global $woo_options;

$selected_layout = 'one-col';
$layouts = array( 'three-col-left', 'three-col-middle', 'three-col-right' );
if ( is_array( $woo_options ) && array_key_exists( 'woo_layout', $woo_options ) )             { $selected_layout = $woo_options['woo_layout']; }

if ( in_array( $selected_layout, $layouts ) ) {

if ( woo_active_sidebar( 'secondary' ) ) {

    woo_sidebar_before();
?>
<aside id="sidebar-alt">
<?php
woo_sidebar_inside_before();
woo_sidebar( 'secondary' );
woo_sidebar_inside_after();
?>
    </aside><!-- /#sidebar-alt -->
<?php
    woo_sidebar_after();
} // End IF Statement
} // End IF Statement
?>

I think there are a few ways to achieve this:

1) We use a conditional function to display the secondary sidebar (which should be on the left of main content) only on category pages. 2) We can disable the secondary sidebar on the single pages. 3) Use CSS to disable sidebar (not sure if this can cause hidden content issue)

I wonder if this sounds logical (unfortunately, I am not a "coder")

Appreciate your help.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Use the is_category() WordPress function to determine if you are in a category template.

<?php
/**
 * Alternate Sidebar Template
 *
 * If a `secondary` widget area is active and has widgets,
 * and the selected layout has a third column, display the sidebar.
 *
 * @package WooFramework
 * @subpackage Template
 */

// If this is a category template.
if ( is_category() ) {

    global $woo_options;

    $selected_layout = 'one-col';
    $layouts = array( 'three-col-left', 'three-col-middle', 'three-col-right' );
    if ( is_array( $woo_options ) && array_key_exists( 'woo_layout', $woo_options ) ) {
        $selected_layout = $woo_options['woo_layout'];
    }

    if ( in_array( $selected_layout, $layouts ) ) {

    if ( woo_active_sidebar( 'secondary' ) ) {

        woo_sidebar_before();
    ?>
    <aside id="sidebar-alt">
    <?php
    woo_sidebar_inside_before();
    woo_sidebar( 'secondary' );
    woo_sidebar_inside_after();
    ?>
        </aside><!-- /#sidebar-alt -->
    <?php
        woo_sidebar_after();
    } // End IF Statement
    } // End IF Statement
}
share|improve this answer
    
Thanks! This code does not work though. I thought it was because I did not select the layout mentioned in the code, (I use two-column-left) so I changed your code to the following: '$layouts = array( 'three-col-left', 'two-col-left','three-col-middle', 'three-col-right' );' This shows the secondary sidebar's widget, but not to the left -- at the bottom of the page. Appreciate your help. –  Sid Aug 11 '13 at 4:13
1  
The question was: Is there a way to show this second sidebar only on category pages? The only test is: Does the sidebar show on only the category pages? Where it appears on the page is another issue. Solve this problem first, then move on to adding the sidebar to the correct place. –  Charles Clarkson Aug 11 '13 at 17:32
    
Great. I guess I will have to ask another question on this topic. Thanks! –  Sid Aug 12 '13 at 4:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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