Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The default behaviour for monthly and yearly archives is to get a set of posts for that period (limited by the max-posts-per-page setting) and show them in full, with paging. I would like a different behaviour for yearly archives (it would seem more natural in most blogs to me, BTW) : show a list of all posts for that year -like an index-, perhaps with excerpts. Which would be the recommended way?

share|improve this question
add comment

1 Answer 1

if you only want this for yearly archives, then you could create a custom date.php template that limits the posts to displaying just the title (and possibly excerpt as you wish)

http://codex.wordpress.org/images/1/18/Template_Hierarchy.png

otherwise, you could also create archive.php but it that would effect all your archives. date.php would only apply to your time-based archives.

then i'd modify the query using pre_get_posts() to override the posts_per_page parameter.

pre_get_posts for modifying the query: http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Example:_Changing_the_number_of_posts_per_page.2C_by_post_type

you said you only want this on the year archives, so we'll use the conditional is_year()

http://codex.wordpress.org/Conditional_Tags#Any_Archive_Page

add this to your functions.php:

add_action('pre_get_posts', 'wpa_44980' );

function wpa_44980( $wp_query ) {

    if( is_year() ) {
        set_query_var('posts_per_page', '-1');
    }
}
share|improve this answer
add comment

Your Answer

 
discard

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.