我目前正在WordPress中使用一个模板(Point from MyThemeShop),它对我来说运行得很好。我已经进行了一些自定义,但有一个问题。
该主题提取最新的帖子,并将其显示在页面顶部的"特色帖子"区域中。我想对这里显示的帖子进行更多的控制,所以我设置了一个类别(主页特色帖子)来更好地定义哪些帖子应该显示在那里。然而,在这个领域工作得很好,最近的帖子提要是。缩略图预览按字母顺序拖动并显示类别名称。因此,如果我有一篇专题文章也被归类为"评论",预览缩略图目前显示的是"主页专题文章",而不是"评论"。我想排除"主页特色文章"出现在这些缩略图中(以及我定义的另一个类别,"趋势文章")。
在索引模板中,似乎提取类别名称的代码是:
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="nofollow" id="featured-thumbnail">
<?php echo '<div class="featured-thumbnail">'; the_post_thumbnail('featured',array('title' => '')); echo '</div>'; ?>
<div class="featured-cat"><?php $category = get_the_category(); echo $category[0]->cat_name;?></div>
<?php if (function_exists('wp_review_show_total')) wp_review_show_total(true, 'latestPost-review-wrapper'); ?>
</a>
我试过一种排除方法,有点奏效。但最终没有提取任何类别,而是在第4行使用这种方法:
<div class="featured-cat"><?php $category = get_the_category(); echo $category[0]->cat_name !--'Homepage Featured Post';?></div>
我需要使用特定的类别ID吗?我不确定如何做到这一点。非常感谢您的帮助。
<?php
foreach((get_the_category()) as $cat) {
if ( $cat->cat_name!=='Homepage Featured Post' || $cat->cat_name!=='Trending Articles' ) {
echo $cat->cat_name . ' ';
}
}
?>
你能用上面的代码吗。