Wordpress自定义博客查询

时间:2018-02-28 19:58:51

标签: wordpress loops blogs

我买了一个名为Magazette的模板。 在索引页面,此主题使用循环列出了所有类别的最新博客文章。

if ( have_posts() ) : 
   while ( have_posts() ) : the_post();
       get_template_part( 'templates/template-parts/content-blog', 'beauty' ); //prints posts

我只想列出一个特定类别的文章,不能不使用类别页面。

我的解决方案是

while ( have_posts() ) : the_post();
    if(is_home() && in_category('enjoy')){
        get_template_part( 'templates/template-parts/content-blog', 'beauty' ); //print posts

这很有效。但我想在1页上列出8个帖子。使用此代码,它可以打印随机数量的博客文章。它只是隐藏了其他类别的帖子,但由于the_post(),博客页面最大文章的计数器仍在增加。

有什么方法可以解决这个问题吗?我只想列出特定类别的文章。它必须是1页的8篇文章。这仅适用于索引页面的博客部分。

1 个答案:

答案 0 :(得分:0)

自我回答。

query_posts('cat=113'); //select category for index page blogs!
    while ( have_posts() ) : the_post();

我设法使用此代码过滤查询。但它只需要类别的ID而不是名称。