Susie Posted February 25, 2009 Report Share Posted February 25, 2009 I'm using this to display the recent posts in the sidebar: <?php wp_get_archives('type=postbypost&limit=5'); ?> Got that code from here: http://codex.wordpress.org/Template_Tags/wp_get_archives I tried just using the regular recent posts widget, but there seems to be a bug where it shows only a page on the Pages instead of the posts. So, does anyone know how to add the date to the get_archives tag? Quote Link to comment Share on other sites More sharing options...
shelfimage Posted February 27, 2009 Report Share Posted February 27, 2009 this is completely untested in WP but... I was up really early in the morning yesterday writing this to pull in WP posts for a CMSMS project <?php global $db; $wp_query = "SELECT post_date, post_title, post_category, post_name FROM wp_posts WHERE post_type = 'POST' AND post_status ='publish' ORDER BY post_date DESC LIMIT 5"; $result = mysql_query($wp_query) or die("Error: " . mysql_error()); while($row = mysql_fetch_array( $result )) { $date_format = date("Y",strtotime($row["post_date"])); $post_date = date("m/d/Y",strtotime($row["post_date"])); $post_title = $row["post_title"]; $post_name = $row["post_name"]; $post_cat = $row["post_category"]; echo ''.$post_date.' – '.$post_title.''; } ?> This will produce a list of 5 article dates and titles linked to their full articles like this: 02/26/2009 - Post-Title So here is the tricky part. This uses SEO Pretty URLs and you need to know your permalink structure. The example above uses post-year/post-name If yours uses post-month/post-day/post-year/category/post-name then some changes will be needed: 1st change is to the line $date_format = date("Y",strtotime($row["post_date"])); change to $date_format = date("m/d/Y",strtotime($row["post_date"])); The second change is to this I would add this into your sidebar template - let me know how it works out. Quote Link to comment Share on other sites More sharing options...
Susie Posted February 27, 2009 Author Report Share Posted February 27, 2009 Oh cool! Thanks John! I will give it a try today and let you know how it goes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.