?
Solved

Wordpress Sidebar - Show posts grouped by month

Posted on 2014-12-09
2
Medium Priority
?
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
eemit earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Wordpress Horizontal Drop-Down Menu In this tutorial I will show you had to add a WordPress horizontal navigation menu to your theme. I have searched and searched for a good tutorial on creating a WordPress nav menu without adding a plug-in or us…
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 Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
Suggested Courses

801 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