Archives by Year

  • Posted in : Editor
  • cyi101
    Participant

    Hey, how’s it going? Love the template, thank you so much for it!

    I’d like to display the Archives separated by Year, kind of similar to this: http://markmanson.net/archive/

    I think the easiest way to do that is to edit the “template-archives.php” file. Specifically this section:

    $args_loop = array( 'post_type' => 'post', 'posts_per_page' => 9999999 );
    $loop_custom = new WP_Query( $args_loop );
    
    if ( $loop_custom->have_posts() ) :
    	while ( $loop_custom->have_posts() ) : $loop_custom->the_post();
    

    Can you show me how to edit this section so that it will only show posts for a specific year? Then I can just copy it and duplicate it for each year I want to recreate.

    Thank you!

    serkan
    Moderator

    Hi cyi101,
    Instead of editing the php file you can try to use this plugin.
    https://tr.wordpress.org/plugins/simple-yearly-archive/
    Thanks

    cyi101
    Participant

    Thanks for the link, but I don’t like the look of the plugin. I’d rather keep the look of your Archives page, but just do a simple modification to the php file.

    Can you show me what to change in that block of code (from “template-archives.php”) so I can bring in certain years? For example, if you show me how to modify this so only entries from 2016 show up, I can figure out how to do it for the other years:

    $args_loop = array( 'post_type' => 'post', 'posts_per_page' => 9999999 );
    $loop_custom = new WP_Query( $args_loop );
    
    if ( $loop_custom->have_posts() ) :
    	while ( $loop_custom->have_posts() ) : $loop_custom->the_post();
    

    Thank you!

    serkan
    Moderator

    Hi cyi101,
    When you update the theme, your customization will gone. Are you going to create a child theme ?

    cyi101
    Participant

    Yes, I’ll be using a child theme. So I’d love to know how to modify that block of code to show only a certain year. Then I can figure out the rest myself, thank you!

    Mehmet S.
    Keymaster

    Hi, you can use the 'year' parameter.

    $args_loop = array( 'post_type' => 'post', 'posts_per_page' => -1, 'year' => 2016 );
    
    cyi101
    Participant

    Thank you Mehmet, that was exactly what I needed! You guys are awesome :)

    serkan
    Moderator

    You’re welcome, please don’t forget to rate the theme on themeforest if you liked it, thanks.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in and have valid license to reply to this topic.

License required for the following item
Login and Registration Log in · Register