Solved

Wordpress Sidebar - Show posts grouped by month

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Nowadays, it is so easy to get started with a website and all thanks to the Content Management Systems (CMS) like WordPress, Drupal, Joomla, and many others like them. However, if we talk about the reliability and ratings, WordPress definitely rules…
SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
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…
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…

696 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