在第4-6行中,我插入了三个条件语句,以确定post在哪个post类型中,这样我就可以插入一个span,用于插入图像。我写的方式不管用。我需要用什么语句?还有更简单的方法来设置这个吗?
<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>对于类别,我通常使用in_category。有类似于in_post_type的东西吗?
发布于 2011-02-23 05:10:26
如果使用is_singular(),也会检查它是否是页面上的单数项。做$post->post_type == 'my-post-type'代替。
顺便说一句:如果你使用post_class(),你就会自动完成这个和更多的任务。
https://wordpress.stackexchange.com/questions/10165
复制相似问题