• Hi — not sure if support is provided for beta releases, but here goes ??

    I’m running 2.5-RC1, which includes Pages as well as Posts in search results. Right now, my search template applies Post formatting, which includes meta info like author and date. For any Pages included in results, I’d like to modify the template to use Page formatting (i.e., no meta).

    How would I do this? Right now, I’m adjusting formatting based on comments_open (Posts always have comments open, Pages always have comments closed), but I’d like to identify pages more precisely.

    Thanks for any help!

Viewing 1 replies (of 1 total)
  • Hi — I’ve searched the support to find an answer to exactly the same question, but didn’t find it.

    Browsing through the WP-code, I finally found a function called get_post_type(), which allowed me to do the trick! You can retrieve the post-type for a certain post/page, by use get_post_type($id) in the loop.

    <?php if (have_posts()) : ?>
          while (have_posts()) : the_post();
          $posttype = get_post_type($id);
    if ($posttype == 'post') { ?>
          Content on how you want to show POSTS.
    <?php } else { ?>
          Content on how you want to show PAGES.
    <?php } ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Distinguish Posts and Pages in WordPress 2.5 search results’ is closed to new replies.