我有一个自定义类别模板,它工作正常,显示了6个不同类别的帖子。在我添加了两个新类别后,所有的类别页面都变得疯狂,2个类别页面显示的帖子过滤错误,尽管所有类别页面在H1中仍然显示正确的类别标题。我正在为几个html块使用模板部分。
从哪里开始检查错误?
我还注意到
$category = get_the_category(\'\');
var_dump($category);
其中一个类别现在有一个类别父级,我可能错误地选择了它,但取消选择它显然并没有修复关系。这是我的主要类别帖子模板:
<?php
$category = get_the_category();
$catTerm = $category[0]->cat_name;
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 1,
\'featured\' => \'featured\',
\'post_status\' => \'publish\',
\'category_name\' => $catTerm
);
$lastPost = new WP_Query($args);
if( $lastPost->have_posts() ):
echo \'<div id="mainArticleBox">\';
while( $lastPost->have_posts() ): $lastPost->the_post();
// get_template_part(\'content\', \'featured-big\');
if (has_post_thumbnail()) :
$category = get_the_category( $id );
echo \'
<div class="hero-img" style="background-image: url(\'
. get_the_post_thumbnail_url() .
\');">
<div class="tag-id hidden-xs hidden-sm">\';
$category = get_the_category();
echo \'<a href="\'.get_category_link($category[0]->cat_ID).\'">\' . $catTerm. \'</a>
</div>
</div>
\';
echo \'
<div class="mainArticle-texts">
<h1 class="h1"><a href="\' . get_permalink() . \'">\' . get_the_title(). \'</a></h1>
<div class="excerpt"><a href="\' . get_permalink() . \'"> <span>\' . excerpt(30) . \'</span> </a></div>
</div>
</div>\';
endif;
endwhile;
endif;
?>