Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Sidebars & Widgets (http://forum.bytesforall.com/forumdisplay.php?f=14)
-   -   [SOLVED] Conditional Tag to exclude widget (http://forum.bytesforall.com/showthread.php?t=1837)

d_random May 29, 2009 10:21 AM

[SOLVED] Conditional Tag to exclude widget
 
Hi-

What would be the conditional tag to exclude a widget on a specific page?
For example, I wanted a widget to appear on all pages except a page with id "16".
What would be the conditional tag for that?

Thanks for your time! :)
donny

juggledad May 31, 2009 05:20 PM

Ok it's not too hard, but some investigation is required.

Lets say you have an 'About' page and you have added the 'Meta' widget to the sidebars, but you don't want it to be displayed on the 'About' page.

First you have to find out what page id the 'About' page is. Go to the WP dashboard and select pages. When you put your cursor over the 'About' link, you will see the page id in the address bar at the bottom (if you are displaying them). You can also go to the front end and go to the page in question and look at the HTML address. It should end in a number, this is the page ID. In this example we will say it is '2'.

Next we need to find out the ID of the widget in question. If you view the source of the page you need to look thru till you find the left or right sidebar (depending on where the widget is) and then you will see something like this

HTML Code:

<!-- Right Sidebar -->
<td id="right">

        <div id="meta" class="widget widget_meta">                        <div class="widget-title"><h3>Meta</h3></div><div class="widget-content">                        <ul>
                <li><a href="http://192.168.48.99/~paul/zenofmud/wp-admin/">Site Admin</a></li>                        <li><a href="http://192.168.48.99/~paul/zenofmud/wp-login.php?action=logout&amp;_wpnonce=4c3f0aa1d6">Log out</a></li>
                <li><a href="http://192.168.48.99/~paul/zenofmud/?feed=rss2" title="Syndicate this site using RSS 2.0">Entries <abbr title="Really Simple Syndication">RSS</abbr></a></li>
                <li><a href="http://mydomain.com/?feed=comments-rss2" title="The latest comments to all posts in RSS">Comments <abbr title="Really Simple Syndication">RSS</abbr></a></li>
                <li><a href="http://wordpress.org/" title="Powered by WordPress, state-of-the-art semantic personal publishing platform.">WordPress.org</a></li>
                                                </ul>
                </div></div><div id="archives" class="widget widget_archive"><div class="widget-title"><h3>Archives</h3></div><div class="widget-content">                <ul>
                        <li><a href='http://mydomain.com/?m=200905' title='May 2009'>May 2009</a></li>
        <li><a href='http://mydomain.com/?m=200904' title='April 2009'>April 2009</a></li>
        <li><a href='http://mydomain.com/?m=199911' title='November 1999'>November 1999</a></li>
                </ul>
</div></div>
</td>
<!-- / Right Sidebar -->

in this case we look for the Meta Widget and find id="meta". Now we have what we need.

go to ATO-> HTML/CSS Inserts -> CSS Inserts and add the following

HTML Code:

#body-page-NN #XXXXXX { display:none; }
where NN is the page number and XXXXXX is the id of the widget, so in this case it would be

HTML Code:

#body-page-2 #meta { display:none; }
and that should be it. Now whenever page 2 is viewed, the META widget won't be displayed.

d_random Jun 1, 2009 07:43 AM

Thank you Juggle!
I have "Widget logic" plug in on all my widgets, which allows you control the widget's behavior with conditional tags. Is there a conditional tag that can be used to exclude it from specific pages? :confused:

juggledad Jun 1, 2009 08:08 AM

If you follow the link on the "Widget logic"'s page in the line:
HTML Code:

The text field lets you use WP's Conditional Tags, or any general PHP code.
it will show you all the conditional tage WordPress supports.

I think the one you ate looking for is 'is_page('22')

d_random Jun 1, 2009 10:46 AM

Juggle-

I think that tag is for including the widget only a specif page. 'is_page('22') would include the widget only on page "22". Is there a tag to include the widget on every page EXCEPT page "22"?

Thank you for your help!! :)
d

juggledad Jun 1, 2009 12:43 PM

is_page('22') = is page 22

!is_page('22') = is NOT ipage 22

d_random Jun 1, 2009 01:46 PM

Juggle!!

That WORKED!!! Thank YOU! :):):)

One more question... If I wanted to exclude the home page too, what would be the tag? I used this code below, but it is not working for the home page, only page "22" :

!is_page(array(22,'home'))

What am I doing wrong?

Flynn Jun 2, 2009 03:46 AM

The page slug for your home page is probably not "home" but nothing ("/")

That "home" would work if you had a static front page and the blog home page was on a page with the page slug "home" http://www.yoursite.com/home/

Use

!is_page('22') AND !is_home()

for the (blog) home page, or

!is_page('22') AND !is_front_page()

for the front page

d_random Jun 2, 2009 07:23 AM

Thanks Flynn!!! :)
This one worked.

!is_page('22') AND !is_home()


All times are GMT -6. The time now is 03:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.