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.

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

1 Answer 1

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. –  songdogtech Jun 1 '11 at 1:23

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.