2016-07-13 180 views
1

全部,WordPress的分類頁面顯示所有博客文章

希望有任何幫助!剛接管一個網站,並與類別頁面有問題。他們目前正在顯示所有博客帖子,而不僅僅是屬於他們的類別。我很確定這個問題可以在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'); 
    } 
    ?> 

任何建議將受到歡迎,謝謝!

回答

0

一旦你創建了一個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的法典更多信息。 https://codex.wordpress.org/Category_Templates

相關問題