WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The code below enables an archive of posts in date order. But I can't figure out how to change this so it only pulls one category of posts.


Any help greatly appreciated


//* Template Name: Custom Archive

//* Remove standard post content output
remove_action( 'genesis_post_content', 'genesis_do_post_content' );
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );

add_action( 'genesis_entry_content', 'sk_page_archive_content' );
add_action( 'genesis_post_content', 'sk_page_archive_content' );
 * This function outputs posts grouped by year and then by months in descending order.

function sk_page_archive_content() {

    global $post;

        $lastposts = get_posts('numberposts=-1') ;
        $year = '';
        $month = '';
        foreach($lastposts as $post) :

            if(ucfirst(get_the_time('F')) != $month && $month != ''){
                echo '</ul></li>';
            if(get_the_time('Y') != $year && $year != ''){
                echo '</ul></li>';
            if(get_the_time('Y') != $year){
                $year = get_the_time('Y');
                echo '<li><h2>' . $year . '</h2><ul class="monthly-archives">';
            if(ucfirst(get_the_time('F')) != $month){
                $month = ucfirst(get_the_time('F'));
                echo '<li><h3>' . $month . '</h3><ul>';

                <span class="the_date"><?php the_time('d') ?>:</span>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <?php endforeach; ?>


remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );

share|improve this question
Please wrap the external links. – Maruti Mohanty Feb 12 '14 at 11:10
Have a look at the parameters that goes with get_posts – Maruti Mohanty Feb 12 '14 at 11:17

Perhaps you can add the category to this line:

$lastposts = get_posts('numberposts=-1&category=7');

Replacing 7 with whatever category ID you need to use.

Link to the WordPress Codex page get_posts() - Parameters.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.