Create your query for the category, and order by date
$q = new WP_Query('category_name=acategory&orderby=date&order=DESC');
After that, while looping posts, save the year in a helper variable, shoing it only when changed:
$year = 0;
if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
$post_year = (int) get_the_time('Y');
if ( $post_year !== (int) $year ) {
echo '<h2>' . $post_year . '</h2>';
$year = $post_year;
}
// the loop
echo '<p><a href="' . get_permalink() . '">' . get_the_title() . '</a></p>';
endwhile;
endif;
wp_reset_postdata();
unset($year, $post_year);
Related Posts:
- Archive.php filtered by pre-determined category
- Category archive by year with permalink support /category/YYYY
- get_categories for custom post type with a specific custom taxonomy attached
- Force WordPress to Show Pages Instead of Category
- Decreasing the Memory Consumption of a WordPress Site?
- How to get the category of the post and link it to the archive (of the category)
- Different templates for parent and children categories/taxonomies
- How to hide a specific category posts in my monthly archive?
- Display posts links from a category group by year
- Display list of Sub-Categories and the posts they contain, within one main Category
- Sort category page with custom field
- How to create tabled index of posts in a certain category
- Exclude a category from the filed under list only on some templates
- Category Specific Archive
- How to have Multiple Archives Widgets, one archive widget per category (in a different page)?
- “Sticky” posts for each category (archive.php)
- How to override Category rendering mechanism
- How to control template resolution if both Author and Category filter in place?
- How to filter archives both by category and tag?
- Display “add to cart” button on every listing in product category page?
- Custom page for WooCommerce’s /product-category/
- Code to pull in a PHP file named after the category ID
- conditional for sub category on archive page
- WP_Query() returns null when results exist!
- How to make a Thumbnails Mosaic
- Are Category or Tag Archive Pages Possible?
- Possible to make a subdirectory that loops through a single category?
- WooCommerce IF statements not working
- Set a them for all subset of category
- Show archives by year from just one category
- How to display only posts assigned to a particular, isolated, subcategory
- Archives for each category on WP Multisite
- How do I call posts with a certain tag?
- Category being displayed without base parmalink
- Restoring default article pagination on archives – Removing custom limits
- Category archive rewrite rule to include category/subcategory?
- The default code for “posts_nav_link” on category.php isn’t working
- Only one post is showing on category page, why?
- Categories overview that links to page displaying posts
- How can I get categories IDs if multiple categories requested via URI?
- Category archives with monthly pagination
- Does “show_option_all” in wp_list_categories do anything?
- How can I improve this taxonomy treating approach?
- How to insert category list into post creation page, and retrieve chosen categories?
- About title on a page
- Image loading function not working on archive.php template
- Custom template for sub-sub-categories
- What Must to Display the “mysite.com/category” URL?
- Using if statement in index.php instead of creating separate template files
- How to display post in custom file not in archive file?
- Why is my sub-category template showing the wrong posts
- Template for product-category page [closed]
- WordPress showing wrong category name
- Display subcategories selectbox on each category page
- Media (images, videos, etc.) not showing on Category page
- Problem with multiple loops in wordpress theme
- what file I need to create to work date archive links?
- Archive filtering
- Category link redirect to custom template page instead of index.php?
- Rebuilding a Site: How to Show Several Category Posts in Woo Framework Theme?
- Displaying a custom field in Category Archives
- Add multiple orderby with pre get posts
- How can I include custom category and tag base in template files?
- Category Template – Show Last Entry as Featured
- Redirect Problems with Archive Page and GET variables
- Output Title of Post’s Current Category
- Showing different posts on category pages
- Displaying categories in different template problem
- How to list posts from a sub-category that is listed in a parent category (more details below)?
- Show the parent taxonomy by creating shortcode in woocommerce?
- How Can I Display the Category Description in a Theme with no Category.php or Archive.php?
- Display Category yearly wise in wp
- How to add excerpt and read more button to category archive page
- custom browse by
- Using a template page parent breaks page
- get_the_terms_list output last child only
- the_content() not showing full posts in category template
- Use different file includes for single.php
- How to get related category/categories in WordPress archive page
- Category archives
- Display Taxonomies in loop with template args
- Choosing different templates for categories
- Getting page/category content to show up in my custom page template
- Conditional statements based on custom meta value in category archives
- date.php shows all posts. how to fix it?
- One category not displaying template updates
- 2 loops in archive.php (one for each category)
- Archives and category of authors
- WordPress a template for subcategories fo a given category, but not for root category
- Category Archives: Show posts categorized in parent category only
- Custom Fields to Category edit page, then displaying them in a template correctly
- Template files not working for archives and categories
- 2 Categories using same template but one has a problem? [closed]
- Why does my category page display “posted on…” when all I want it to do is display categories?
- How to create a template for categories
- All post of child category not in top category
- How to show monthly archive posts?
- How to load/include category templates based on conditionals?
- how to implement next/prev within category archive?
- How to link ACF relationship field to the new Query block in Full Site Editing