簡體   English   中英

Wordpress類別頁面顯示所有博客帖子

[英]Wordpress Category Pages Showing All Blog Posts

所有,

非常感謝任何幫助! 剛接管一個網站,我遇到了類別頁面的問題。 他們目前正在展示所有博客帖子,而不僅僅是那些屬於他們類別的帖子。 我很確定可以在category.php文件中找到該問題。 看起來之前的開發人員通過將其作為博客帖子提交來設置FAQ頁面,請參見下文:

<?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');
    }
    ?>

任何建議都會受到歡迎,謝謝!

創建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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM