Skip to content

Instantly share code, notes, and snippets.

@djgraham
Created November 17, 2009 14:30
Show Gist options
  • Save djgraham/236936 to your computer and use it in GitHub Desktop.
Save djgraham/236936 to your computer and use it in GitHub Desktop.
<?php
/* Wordpress proof of concept -
Loop through posts in a particular category, outputting the first three latest as
"Latest" pages/posts.
Then use the rest as "archived" posts
David Graham, November 2009.
*/
$ul = false;
$previous_month=0;
$counter = 0;
$category_id = 3; // whatever you want this to be!
$archive_posts = get_posts('numberposts=20&offset=0&category='.$category_id);
foreach ($archive_posts as $key=>$archive_post):
$post_month = date("mY",strtotime($archive_post->post_date_gmt));
if ($counter == 3 )
{
if ($ul == true)
{ echo "</ul>";
$ul = false;
}
echo "<h2>Archive</h2>";
$previous_month = 0;
}
if ($post_month != $previous_month)
{
if ($ul == true)
{ echo "</ul>";
$ul = false;
}
echo "<h3>".date("M Y",strtotime($archive_post->post_date_gmt));
echo "</h3>";
echo "<ul>";
$ul = true;
$previous_month = $post_month;
}
echo "<li>" . $archive_post->title."</li>";
$counter++;
endforeach;
if ($ul == true) echo "</ul>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment