Solved

Wordpress Sidebar - Show posts grouped by month

Posted on 2014-12-09
2
207 Views
Last Modified: 2014-12-11
I have a http://www.coreenergetics.com.br/core domain and my client wants in the sidebar appear the last post grouped by month.

I almost got close, but the months are doubling ... how do I make it: (Month + Posts this month) and not (Month + Posts, Posts month + ...)

The code I'm using is:

<ul>
<? php 
   $ aRecentPosts = new WP_Query ("showposts = 10");
    while (aRecentPosts-> have_posts $ ()): $ aRecentPosts-> the_post ();?> 
         <li> <strong> <? php the_time ('F Y')?> </ strong> </ li>
         <li> <a href="<?php the_permalink() ?> "> <? php the_title ()? a> </ li>
   <? php endwhile; ?>
</ ul>

Open in new window

0
Comment
Question by:Waldir-PRG
2 Comments
 
LVL 15

Accepted Solution

by:
eemit earned 500 total points
ID: 40491595
Try this:
<ul>
<?php 
	$aRecentPosts = new WP_Query( array ( 'showposts' => '10', 'orderby' => 'm', 'order' => 'DESC' ) );

	$year_month = '';
	$post_year_month = '';
	while ( $aRecentPosts-> have_posts() ): $aRecentPosts-> the_post(); 
		$post_year_month = get_the_time ('F Y');
		if ( $year_month !== $post_year_month ) {
		?>
			<li><strong><?php esc_html_e( $post_year_month ); ?></strong></li>
		<?php
			$year_month = $post_year_month;
		}
		?>
		 <li><a href="<?php the_permalink(); ?>"><?php the_title();?></a></li>
	<?php
	endwhile;
	wp_reset_postdata();
	?>
</ul>

Open in new window

0
 

Author Closing Comment

by:Waldir-PRG
ID: 40493501
Fantastic ! Tks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What's this? As a volunteer Page Editor for Experts-Exchange.com, I have noticed that many authors also have blogs, and pull articles from their blogs to post at Experts-Exchange. I appreciate each author sharing their blog content with our site …
An earlier version of this article was originally posted on my personal blog at: ​http://www.brianjmatis.com/2014/07/07/enabling-nextprevious-post-links-in-wordpress/ Introduction In most blogs, a fairly common navigational element is to have li…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question