post-page

Using Conditional Statements In WordPress

8
responses
by
 
on
October 22nd, 2009
in
WordPress
heading
heading
heading
8
Responses

 

Comments

  1. Adam W. Warner (1 comments.) says:

    My WP development hands would be tied without Conditional Statements + Widget Logic.

  2. Jessi Hance (4 comments.) says:

    I use them in my theme header to set the page title, depending on what kind of page it is. A lot of people do that, I guess.

    I also use them to create meta descriptions. On single post pages, the post excerpt is used for the meta description. On “page” pages, it uses a custom field where I put in whatever description I want for that page; and on the home page, I just echo out the meta description I want.

    These bits of code enabled me to stop using a couple of SEO plugins. I have a lot of plugins and I’m always glad to find a way to prune them.

    Oh, I also use them to do menu highlighting, and to control the content of the sidebar based on which page it is.

  3. Matt (23 comments.) says:

    Conditional statements are truly amazing. I use them for:

    1. Displaying a different layout graphic for home view and single/archive/page/search/other views.

    2. Styling a post differently for the “mature audiences only” category so that there is a verification link to show the content instead of just outright displaying it (both in archive/category/search view and single view).

    3. Sidebar shenanigans for home/single/page.

    I’m sure I’ll come up with some more ways to use them and trim the fat out of the theme code in the future.

  4. Jake Spurlock (1 comments.) says:

    I use conditional tags to show/hide content based on if the user is logged in or not.

    Ex. If the user isn’t logged in, when they get to an event registration page, they are told to register or login, if they are, then they can see the page and register.

    I have also done the same thing with ads, show create account buttons, but turn them off once they have logged in. Wrote up a blog post about it too…

    http://soul.petomundo.com/2009.....wordpress/

  5. One Fine Jay (1 comments.) says:

    I use it to nuke comments from pages.

  6. jason (1 comments.) says:

    category pages – each category has its own icon next to the category name (it’s a sports blog, so each category has the logo of the appropriate team). conditional statement lets me display different logos via a different css class on different category pages without creating a zillion new templates.

  7. Tony (4 comments.) says:

    This sounds like something I have been looking for, thankls for bringing it to my attention.

    I have been trying to find a way to display a different advert block in the sidebar, depending on the country that a visitor is from.

    I know the conversion from IP Address to country is not bulletproof, but if I could for example display UK related ads to visitors from the UK and USA related ads to visitors from the USA (and use this as a default), it could make a difference to my potential revenue.

    Initially I have thought to use this for adverts, but there are many other uses, like displaying variable RS Feeds.



Trackbacks/Pingbacks

  1. […] Using Conditional Statements In WordPress […]

Obviously Powered by WordPress. © 2003-2013

page counter
css.php