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; ?>

1 Answer 1


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

  • Didn't know the difference in the conditional tags. That works great. Thanks. Commented Jun 1, 2011 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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