Solved

Wordpress Sidebar - Show posts grouped by month

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
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. …

730 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