【问题标题】:Wordpress Category Pages Showing All Blog Posts显示所有博客文章的 Wordpress 类别页面
【发布时间】:2016-11-15 11:17:54
【问题描述】:

全部,

不胜感激!刚刚接管了一个网站,但在类别页面上遇到了问题。他们目前正在显示所有博客文章,而不仅仅是属于他们类别的文章。我很确定这个问题可以在 category.php 文件中找到。看起来之前的开发者通过将它们作为博客帖子提交来设置常见问题页面,见下文:

<?php foreach((get_the_category()) as $category) { 
        $cat_id =  $category->cat_ID; 
    }

    if ($cat_id == 38 or $cat_id == 49 or $cat_id == 47 or $cat_id == 48){
        get_template_part( 'content','faq');
    }
    else{
        get_template_part( 'content','blog');
    }
    ?>

欢迎提出建议,谢谢!

【问题讨论】:

    标签: php wordpress blogs


    【解决方案1】:

    创建 category.php 文件后,WordPress 会自动将其识别为类别模板,因此您只需像往常一样使用 The Loop。

    您可以使用一些功能,例如:

    <p>Category: <?php single_cat_title(); ?></p>
    

    或

    <?php if (is_category('Category A')) : ?>
    <p>This is the text to describe category A</p>
    <?php elseif (is_category('Category B')) : ?>
    <p>This is the text to describe category B</p>
    <?php else : ?>
    <p>This is some generic text to describe all other category pages, 
    I could be left blank</p>
    <?php endif; ?>
    

    您可以在 WordPress Codex 中获得更多信息。 https://codex.wordpress.org/Category_Templates

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-26
      • 1970-01-01
      • 2019-04-16
      • 2012-01-31
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多