0

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.

1 Answer 1

1

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
}
3
  • 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
    Commented Aug 11, 2013 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. Commented Aug 11, 2013 at 17:32
  • Great. I guess I will have to ask another question on this topic. Thanks!
    – Sid
    Commented Aug 12, 2013 at 4:27

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.