Wordpress 如何在此查询中从单个类别返回结果?

Wordpress 如何在此查询中从单个类别返回结果?,wordpress,Wordpress,如何在此查询中返回类别84中的最新帖子 <?php /*$args = array('post_type'=>'post', 'posts_per_page'=>'10', 'post_no_in'=>$do_not_duplicate);*/ $args = array('post_type'=>'post', 'post_no_in'=>$do_not_duplicate); $que

如何在此查询中返回类别84中的最新帖子

<?php
            /*$args = array('post_type'=>'post', 'posts_per_page'=>'10', 'post_no_in'=>$do_not_duplicate);*/
            $args = array('post_type'=>'post', 'post_no_in'=>$do_not_duplicate);
            $query = new WP_Query($args);
            query_posts("cat=84&showposts=1&orderby=DESC");
            if($query->have_posts()){
            while(have_posts()) : the_post();   
            /*$do_not_duplicate[] = get_the_ID();*/  ?>
            <div>
               <?php the_post_thumbnail(); ?>
                 <div class="instruction">
                <div class="home_title">MOST READ</div>
                <div class="home_title_desc"><h3><a href="<?php the_permalink(); ?>"><?php echo the_title(); ?></a></h3></div>
                 </div>
            </div>

        <?php endwhile; ?>
        <?php } ?>  

大多数阅读
我在数组中尝试了'cat'=>84,但没有成功。你能告诉我如何只返回84类的结果吗?
谢谢

ahh,
query_posts(“cat=84&showposts=1&orderby=DESC”)

此代码非常混乱,实际上试图连续运行两个查询;其中一个使用
query\u posts()
,这从来都不是一个好主意(解释一下)

以下是为您重新编写的查询,根据请求从类别84获取最新帖子:

$args = array(
    'post_type' => 'post',
    'category__in' => 84,
    'order' => 'DESC',
    'posts_per_page' => 1,
);

$query = new WP_Query($args);

if($query->have_posts()){
    while(have_posts()){
        the_post();
        // do stuff here...
    }
}
有关每个参数的作用的信息,请参阅。特别是,
posts\u per\u page
参数告诉Wordpress只为您返回一篇文章


我省略了原始代码中的
'post\u no\u in'=>$do\u not\u duplicate
,因为我不确定它在做什么,但是如果您想问这个问题,请尽管问,或者您可以在WP\u查询文档中找到适当的参数,并将其添加到上面的
$args
数组中。

注意这一点。您好,我已经编辑了这个问题以添加所有代码,因为每次我输入您的代码时,我都一无所获,您能帮我解决这个问题吗?谢谢一堆你说什么“一无所获”?查询不返回帖子?插入上面重写的查询后,你能编辑代码的外观吗?如果我插入你的代码,并在我得到一个白色页面时将结束括号放在结束括号之后。这意味着有某种PHP错误。你能打开WP_DEBUG(Google for how)并编辑你的帖子来展示你下载的代码的外观吗?我还建议你做一个在线PHP教程,因为掌握一些基础知识将有助于你调试自己的代码。StackOverflow并不是真正意义上的代码编写服务;它可以帮助您解决在自己的代码中遇到的概念。试试类似或