简体   繁体   English

从WordPress模板中排除类别名称(不包括帖子)

[英]Excluding a Category Name (Not Posts) From A WordPress Template

I'm currently working with a template (Point from MyThemeShop) in WordPress that has been functioning fairly well for me. 我目前正在使用WordPress中的模板(MyThemeShop中的Point),该模板对我来说运行良好。 I've already made some customizations but am having one issue. 我已经进行了一些自定义,但是遇到了一个问题。

The theme pulls the most recent posts and displays them in a "Featured Posts" area at the top of the page. 该主题提取最新的帖子,并在页面顶部的“精选帖子”区域中显示它们。 I wanted more control over the posts displayed here so I set up a category (Homepage Featured Posts) to better define which posts should show up there. 我想更好地控制此处显示的帖子,因此我设置了一个类别(“首页精选帖子”)以更好地定义应该在此处显示的帖子。 Works well, however, under this area where the recent post feed is . 但是,在最近发布的Feed所在的区域下,效果很好。 . . the thumbnail previews pull and display the category name in alphabetical order. 缩略图预览拉出并按字母顺序显示类别名称。 So, if I have a featured post categorized under "Review" also, the preview thumbnail currently says "Homepage Featured Post" instead of "Review". 因此,如果我也有一个精选帖子也归类为“评论”,则预览缩略图当前显示的是“首页精选帖子”,而不是“评论”。 I would like to exclude "Homepage Featured Post" from showing up in these thumbnails (and one other category I've also defined, "Trending Articles"). 我想从这些缩略图(以及我也定义的另一类,“趋势文章”)中排除“主页精选文章”。

In the Index Template the code that seems to pull the category names is this: 在索引模板中,似乎拉出类别名称的代码是这样的:

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

I've tried an exclusion method that sort of worked . 我尝试了一种行之有效的排除方法。 . . but ended up not pulling ANY categories instead, using this method on line 4: 但最终没有在第4行使用此方法提取任何类别:

<div class="featured-cat"><?php $category = get_the_category(); echo $category[0]->cat_name !--'Homepage Featured Post';?></div>

Do I need to use specific category ID's? 我是否需要使用特定的类别ID? I am unsure how to accomplish this. 我不确定如何做到这一点。 Any help is much appreciated. 任何帮助深表感谢。

<?php
    foreach((get_the_category()) as $cat) {
        if (    $cat->cat_name!=='Homepage Featured Post' || $cat->cat_name!=='Trending Articles' ) { 
            echo $cat->cat_name . ' ';
        }
    }
?>

Can you use above code. 您可以使用上面的代码吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM