类别页面的Wordpress MySQL查询

类别页面的Wordpress MySQL查询,mysql,wordpress,categories,Mysql,Wordpress,Categories,我在我的wordpress index.php上使用这个查询来显示文章,并按日期(最早的第一个ASC)对它们进行排序。我之所以使用这个数据库查询,是因为出于某种原因,查询帖子对我不起作用 现在我想在我的分类页面上使用完全相同的查询。我不知何故不得不添加一些行,以便只显示活跃类别的帖子 有人有解决方案吗?好的,根据您发布的信息,您可以使用以下内容: $args = array( 'post_status' => array( 'publish', 'future' ), 'post_typ

我在我的wordpress index.php上使用这个查询来显示文章,并按日期(最早的第一个ASC)对它们进行排序。我之所以使用这个数据库查询,是因为出于某种原因,查询帖子对我不起作用

现在我想在我的分类页面上使用完全相同的查询。我不知何故不得不添加一些行,以便只显示活跃类别的帖子


有人有解决方案吗?

好的,根据您发布的信息,您可以使用以下内容:

$args = array( 'post_status' => array( 'publish', 'future' ), 'post_type' => 'post','orderby' => 'date', 'order' => 'ASC' );

$the_query = new WP_Query( $args );


while ( $the_query->have_posts() ) :
        $the_query->the_post();
        the_time('l, F jS, Y');
        the_content();
        the_category();
endwhile;


wp_reset_postdata();
根据请求更新
get_header();?>
这是一个twentytweleve类别页面,显示:

您不需要使用
$wpdb
使用
wp\u query
而不是
query\u posts
@DavidChase谢谢,您能给我一个如何在我的场景中使用wp\u query的示例吗?我想显示活动类别的所有帖子(发布和未来),并按日期升序排序。提前谢谢!在所有活动类别中?你能说得更具体些吗?你想要一个类别中的所有帖子吗?对不起。我只想要一个普通的类别模板。所以基本上我想要的是正常的分类存档,但按升序排列(并显示将来的帖子)。是的,
while
endwhile
是一个循环,在这个循环中,你可以获得存档/分类页面所需的所有内容,比如
the_category()
,等等:解析错误:语法错误,意外的“endwhile”(T_ENDWHILE)在C:\xampp\htdocs\wordpress\wp content\themes\spin\archive.php第96行,你不需要
这个
endwhile
,因为你没有一个打开的while检查你的粘贴箱,也没有
的else
,除非你有一个打开的
如果
好的话,请再次检查:现在它工作了,但它只显示了一个帖子。看起来好像循环没有重新开始,但在显示一篇文章后结束。您可以向我显示您使用我的代码的整个模板/页面吗
get_header(); ?>

    <section id="primary" class="site-content">
        <div id="content" role="main">

        <?php if ( have_posts() ) : ?>
            <header class="archive-header">
                <h1 class="archive-title"><?php printf( __( 'Category Archives: %s' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h1>

            <?php if ( category_description() ) : // Show an optional category description ?>
                <div class="archive-meta"><?php echo category_description(); ?></div>
            <?php endif; ?>
            </header><!-- .archive-header -->

            <?php
            $args = array( 'post_status' => array( 'publish', 'future' ), 'post_type' => 'post','orderby' => 'date', 'order' => 'ASC' );

            $the_query = new WP_Query( $args );


            while ( $the_query->have_posts() ) :
                    $the_query->the_post();
                    the_time('l, F jS, Y');
                    the_content();
                    the_category();
            endwhile;


            wp_reset_postdata();
            ?>

        <?php else : ?>

        <?php endif; ?>

        </div><!-- #content -->
    </section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>