• I’m diving into the world of hooks and filters and need a little advice.

    I want to have the sidebars removed and the content area widened to the full page when product-specific categories used in a single post display. I’ve read up using filters for this, found an example and am modifying it for my use.

    Here is my function code:

    function product_posts_no_sidebar() {
     global $post;
     if ( !is_category() ) return;
     $cats=get_the_category($post->ID);
     foreach($cats as $cat) {
     if( in_array($cat->cat_name,array("store-all")) ) {
     {?>
     <style>
     #secondary { display: none; border: none; }
     .site-content  {width:100%; background}
     </style>
     <?php }
     }
     }
    }
    add_filter('THIS IS MY PROBLEM AREA', 'product_posts_no_sidebar');

    As you can see, I do not know what filter to put in the first part of the add_filter spot. I have read the long list of the Plugin API/Filter Reference on the Codex and I’m not able to determine what filter I would need to reference. Would it be a content reference? I’m not grasping which one would apply.

    What filter would be the appropriate one to place here?

    And then, I have some pages where I want to accomplish the same result (no sidebar and full width content), but this would be by applying it to all my store-specific page templates and not the default page template. So, “all page templates except page.php”.

    Would appreciate some advice. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter David Borrink

    (@davidborrink)

    I can find filters in the widget listing in the Plugin/Filter reference that mention sidebars, but would seem to me to be a bigger thing like page structure rather than a widget issue since I want the sidebar gone for certain categories, so I’d be inclined to this it’s from the page, post and attachment filters list, but they don’t seem to be clear as to which are for page structure setups.

    (You can tell I’m no filters and hooks expert, yet)

    Thread Starter David Borrink

    (@davidborrink)

    Okay, a friend suggested I use the ‘single_template’ filter to run this.

    function product_posts_no_sidebar() {
     global $post;
     if ( !is_category() ) return;
     $cats=get_the_category($post->ID);
     foreach($cats as $cat) {
     if( in_array($cat->cat_name,array("store-all")) ) {
     {?>
     <style>
     #secondary { display: none; border: none; }
     .site-content  {width:100%; background}
     </style>
     <?php }
     }
     }
    }
    add_filter('single_template', 'product_posts_no_sidebar');

    The results: sidebar (#secondary) didn’t disappear. The site-content didn’t go to 100%, but the footers at the bottom of the post and the comment boxes disappeared.

    Completely baffled. I’d think “single_template” was the right choice given that something happened, but why my styling wouldn’t kick in, plus those other items disappeared. Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to filter out sidebars on specific category posts, and some specific pages’ is closed to new replies.