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