WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Different widgets on different pages (5 posts)

  1. sk160770
    Member
    Posted 1 year ago #

    I want to display different widgets on different pages of my site. For example I do not want to show ads on my homepage, instead I would like to show Most Popular posts, while, on the same place, ads on other pages eg. posts, category or archive.
    I think it can be achieved using Conditional Statement (If....Then) but I am unable to figure out how to do this with widgets ?

    Anybody used conditional statements with widgets before ?

  2. rohanpawale
    Member
    Posted 1 year ago #

    There are three ways to do it with widgets

    1]Use raw PHP in the widget itself, which will allow you to use the is_home() conditional tag

    2]Edit your functions.php file and add all widgets through conditional tags. You will need the widget ID for such filtering. This might be easier to edit the widgets.php itself which is the third way

    3]When you open widgets.php you will find a list of all installed widgets something like this :

    <?php include(TEMPLATEPATH . '/includes/widgets/widget-about.php');
    include(TEMPLATEPATH . '/includes/widgets/widget-adsense.php');
    include(TEMPLATEPATH . '/includes/widgets/widget-ads.php');
    ?>

    You can add your conditional tags there.

  3. deepbevel
    Member
    Posted 1 year ago #

    or, try a plugin like dynamic widgets.

  4. sk160770
    Member
    Posted 1 year ago #

    Thank you buddies for your kind help.

Topic Closed

This topic has been closed to new replies.

About this Topic