Solved

Wordpress Sidebar - Show posts grouped by month

Posted on 2014-12-09
2
194 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
This article will shed light on the latest trends when it comes to your resume building needs. For far too long, the traditional CV format has monopolized the recruitment market.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now