我是wordpress的新手,我正在尝试为一个类别(ID为7)显示自定义html div。所以这是我的代码..
<?php if(have_posts()) : ?>
<?php is_category( '7' ); ?>
<?php echo 'test'; ?>
<?php while(have_posts()) : the_post(); ?>
<article <?php post_class(); ?>>
<div class="latest-posts">
<div class="latest-posts-info">
<div class="title"><h1><?php the_title(); ?><h1></div>
<div class="text">
<?php the_excerpt(); ?>
</div>
<a href="<?php the_permalink() ?>" class="read-more">Read more...</a>
<div class="clear"></div>
</div>
<div class="latest-posts-img">
<?php //echo get_the_post_thumbnail(); ?>
<?php custom_get_post_attachments(get_the_ID(), $__width, $__height, get_the_title()); ?>
</div>
<div class="clear"></div>
</div>
</article>
<?php endwhile; else: ?>
<div class="content">
<p class="not-found-p">No articles found!</p>
</div>
<?php endif; ?>
它应显示该类别的TEST,但它不会。怎么了?
谢谢!
答案 0 :(得分:2)
is_category
会返回一个布尔值。您只需在代码中调用它 - 您需要将其包装在if语句中:
if (is_category('7')) {
echo 'TEST';
}
WordPress的文档非常全面,值得一读:
Codex entry for is_category