WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can one differentiate between posts and pages in search results?

What I need to do is show a the_time div for posts but not show it for pages, as it's irrelevant.

With a function? <?php if (!is_page()) } in the loop below doesn't help.

<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>

//prevent this div from displaying for pages: 
<div class="searchdate"><?php the_time('F jS, Y') ?></div>

<?php the_excerpt(); ?>

<?php endwhile; ?><?php else : ?><?php endif; ?>
share|improve this question
up vote 3 down vote accepted

Try this...

<?php //prevent this div from displaying for pages:
if ( get_post_type() != 'page' ) : ?>
   <div class="searchdate"><?php the_time('F jS, Y') ?></div>
<?php endif; ?>

The is_page() conditional tag only checks if currently displayed content is a single page view. Nothing for you at this point. See http://codex.wordpress.org/Function_Reference/is_page

share|improve this answer
Didn't know the difference in the conditional tags. That works great. Thanks. – markratledge Jun 1 '11 at 1:23

Your Answer


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.