• Resolved kennethwatt

    (@kennethwatt)


    Hi
    I have some static widgets in the sidebar.php, and a widget in the dynamic sidebar. I want to hide the dynamic sidebar if the post is in the category “artists”. Does the following code not work as it’s not in the loop?

    <?php if (in_category('Artists')) { ?>
    No dynamic sidebar shown.
    <?php }else{ ?>
    <?php   /* Widgetized sidebar, if you have the plugin installed. */
              if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?><?php endif; ?>
    <?php } ?>

    The above code has been put in the sidebar.php.
    What’s wrong?
    Thanks in advance,
    Kenneth

Viewing 11 replies - 1 through 11 (of 11 total)
  • I actually have almost the same question as you. I might as well ask it here rather than create another thread.

    How can I not display a sidebar when not on my main page. I.E. when displaying a blog post.

    It should be about the same procedure as above.

    If not in the Loop, you need to specify the current post ID as the second parameter for in_category function.

    Perhaps this could help:

    <?php if (in_category('Artists'), $id) { ?>
    No dynamic sidebar shown.
    <?php }else{ ?>
    <?php   /* Widgetized sidebar, if you have the plugin installed. */
              if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?><?php endif; ?>
    <?php } ?>
    Thread Starter kennethwatt

    (@kennethwatt)

    Sorry, stuck your code in – got the following error:
    Parse error: syntax error, unexpected ',' in /****/****/public_html/forecourt.org.uk/wp-content/themes/asusena/sidebar.php on line 44
    Is it because i’m not replacing the $id with an actual number?

    Thread Starter kennethwatt

    (@kennethwatt)

    @zero2heromn
    Should it not just be:

    <?php if (is_front_page()) { ?>
    <?php   /* Widgetized sidebar, if you have the plugin installed. */
              if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    <?php }else{ ?>
    No sidebar. Woohoo.
    <?php endif; ?>
    <?php } ?>

    Thread Starter kennethwatt

    (@kennethwatt)

    That will just hide a dynamic sidebar though. Maybe put conditional tags in the bottom of pages where it says <?php get_sidebar(); ?>.

    Edit the code I gave so that it has <?php get_sidebar(); ?> where it calls the sidebar.

    Sorry for the multiple posts BTW.

    Oh, sorry I put the $id in the wrong place.. My bad..
    Don’t change the $id. I think the $id the ID of the current post.

    Try this:

    <?php if (in_category('Artists', $id)) { ?>
    No dynamic sidebar shown.
    <?php }else{ ?>
    <?php   /* Widgetized sidebar, if you have the plugin installed. */
              if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?><?php endif; ?>
    <?php } ?>
    Thread Starter kennethwatt

    (@kennethwatt)

    Thanks Nazieb that’s great ??

    K

    Thread Starter kennethwatt

    (@kennethwatt)

    Sorry, but I’ve just realised that it’s not displaying on the home page.

    It’s working fine everywhere else.

    Tried changing it to:

    <?php if (in_category('artists', $id)) { ?>
    <?php if (is_home()) ?>
    <?php   /* Widgetized sidebar, if you have the plugin installed. */
              if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    <?php }else{ ?>
    <?php   /* Widgetized sidebar, if you have the plugin installed. */
              if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?><?php endif; ?>
    <?php } ?>

    But comes up with error.

    Sorry – can’t give live URL, as company I’m developing for won’t allow me.

    K

    Thread Starter kennethwatt

    (@kennethwatt)

    Would it be best for me to create another if (is_home)?

    K

    Try this:

    <?php if (in_category('Artists', $id) && !is_home()) { ?>
    No dynamic sidebar shown.
    <?php }else{ ?>
    <?php   /* Widgetized sidebar, if you have the plugin installed. */
              if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?><?php endif; ?>
    <?php } ?>
    sene1983

    (@sene1983)

    hi,
    i wanna try this code,

    <?php if (in_category('Category', $id)) { ?>
    No dynamic sidebar shown.
    <?php }else{ ?>
    <?php   /* Widgetized sidebar, if you have the plugin installed. */
              if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?><?php endif; ?>
    <?php } ?>

    But, to which file i will add this code? To, index.php or page.php
    thanx for your help

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Hide Sidebar if in Category’ is closed to new replies.