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.

On lines 4-6, I've inserted three conditional statements to determine which post type the post is in so I can insert a span which I will use to insert an image. The way I wrote it isn't working. What statement would I need to use? And is there a simpler way to set this up?

    <section id="main">
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <article class="search-post" id="post-<?php the_ID(); ?>">
            <?php if (is_singular('projects')) {echo'<span class="search-projects"></span>';} ?>
            <?php if (is_singular('videos')) {echo'<span class="search-videos"></span>';} ?>
            <?php if (is_singular('friends')) {echo'<span class="search-friends"></span>';} ?>
            <h2><?php the_title(); ?></h2>
            <section class="search-entry">
                <?php the_excerpt(); ?>
            </section>
        </article>
        <?php endwhile; endif; ?>
        <?php my_paginate_links(); ?>
    </section>

For categories, I usually use in_category. Is there something like an in_post_type?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

If you use is_singular(), you're also checking for if it's a singular item on the page. Do $post->post_type == 'my-post-type' instead.

BTW: if you use post_class() you get this and more done automatically.

share|improve this answer
    
Actually according to Codex is_singular() with post type passed should check for that specific post type. I am not sure why would it fail in this specific case. Edit Scratch that, got confused for a moment. is_singular() check for global query, not global post. So not suitable for loop of multiple posts. –  Rarst Feb 23 '11 at 13:14
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.