one widget, different placement depending on page/post (2 posts)

  1. alsd
    Posted 6 years ago #

    I have two widgets that are to be used for a plugin.

    In homepage I want it shows up in non-sidebar section (widget1); in single post it will shows on the sidebar (widget2) and I have it placed in the sidebar.php which contains other widgets that are to be used globally.

    The problem is, widget2 also show up in the homepage sidebar which I don't want.

    I suppose I can create a second template for sidebar which exclude "widget2", but I would like to know if it's possible to use just one template with "is_front_page()" tag.

    I tried using this code but it's not really working as the "widget2" still showing up in the homepage.

    <?php if ( is_front_page() && !function_exists('dynamic_sidebar') || !dynamic_sidebar("widget2") ) : ?>
    <?php endif; ?>

    Have searched the forum but I can't find anything that works for me.

  2. alsd
    Posted 6 years ago #

    Never mind! I got it working with this:

    <?php if (!is_front_page()) {?>
    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("widget2") ) : ?>
    <?php endif; ?>
    <?php }?>

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.