Wordpress 自定义博客查询

Wordpress customizing blog query

我买了一个名为 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().

,博客页面最大文章数的计数器仍在增加

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

自己回答。

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

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