Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'd like a way to target only blog-area pages for specific formatting.

So far,

<?php if (is_home() || is_single() || is_category() || is_archive() ) { ?>

works okay, but is there a way to combine all of those into one single function to shorten it up a bit? so maybe in the functions it would set is_blog() to equal those four (or however many I want).

Seems a bit simple and probably is.... I just dont know what to search for to find information on this. Thanks!!

share|improve this question
    
Hi there ... is_archive should cover is_category ... what type of formating are you trying to do? as its probably better to do this inside The Loop –  Damien Oct 12 '12 at 21:27
add comment

2 Answers

up vote 1 down vote accepted

Based on what you described:

function is_blog()
{
    return ( is_home() || is_single() || is_category() || is_archive() );
}

And then just call the is_blog() function whenever needed.

I also found this, which looks like a more specific way to do the same thing https://gist.github.com/1189639

share|improve this answer
    
awesome! perfect, thank you! –  jamie Oct 15 '12 at 13:53
add comment

All the is_*() »Conditional Tags« are wrappers for their is_* pendants in the global $wp_query object. They all reflect parts of the »Template Hierarchy« which determines which file should be loaded (if present) to display the request.

To make it short here're the most general:

  • is_archive() covers all Tag, Taxonomy, Category, Post Type (Post/Page/Attachments/links/Custom Post Type, etc.) archive pages (there's also is_post_type_archive() to lock those out).
  • is_home() and is_front_page() are basically the same, with the difference, that they distinguish the display setting for the front page: Latest posts & static front page.
  • is_singular() catches all "single" views, like a page, an attachment, a post, etc.
  • is_search() covers search result pages
  • is_404() catches everything ... that wasn't catched

So based on this list, you should be able to wrape up what you need - depending what "blog area pages" are for you.


As a little helper, you can use the functions from this answer that lists all conditionals that are true on a request. This should help you getting around it pretty quick.

Just upload it as a plugin. Deactivate it when you're done.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.