0
votes

I am using this query on my wordpress index.php to display posts and sort them by date (oldest first ASC). I use this database query because query_posts didn't work for me for some reason.

http://pastebin.com/e7vVyKP9

Now I want to use the exact same query on my category pages. I somehow have to add some lines in order to only show posts of the category which is active.

Does anyone have a solution?

1
you do not need to use $wpdb use wp_query instead of query_posts - David Chase
@DavidChase Thanks, can you give me an example of how to use wp_query for my scenario? I want to show all posts (publish & future) of the active category and sort them by date ascending. Thanks in advance! - user2191254
of all active categories? can you be more specific? you want all posts within a category ? - David Chase
sorry. I just want a normal category template. So basically what I want is normal category archives but in ascending order (and showing also future posts). - user2191254

1 Answers

0
votes

Ok so based on your information that you posted you could use something like this:

$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();

UPDATED WITH REQUEST

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(); ?>

This is a twentytweleve category page that displays: this page