Posts Tagged ‘Archive’

Snippet: Yearly Posts with Excerpt (Archive, WordPress, PHP)

Thursday, April 15th, 2010

<?php for($newdate = date("Y"); $newdate>=2005; $newdate=$newdate-1) { ?>
<div style="clear:both;" >
	<h1><?php echo $newdate." ";  ?></h1>
	<?php query_posts("cat=63&year=$newdate" ); ?>
	<?php while (have_posts()) : the_post(); ?>
		<div  style="width:200px; float:left; height:170px;">
			<?php the_excerpt('more_link_text', strip_teaser, 'more_file'); ?> 
			<h4><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to  <?php the_title_attribute(); ?>" ><?php the_title(); ?></a></h4>
	<?php endwhile; ?>
<?php } ?>

After installing and uninstalling severall plugins in WordPress for different purposes I decided to write my first php/wordpress loop for a specific need.

I use post-excerpts for my Category-Overview Sites, displaying the thumbnail-image of the post and the Title – both clickable.

For my EXHIBIT HIGHTLIGHT section which is -short to say- a photo- and videoblog i needed a solution to display this excerpts ordered by year. Some sort of a category archive.

Simply a loop for the year ending with the first post-blog and beginning with the current year. As you can see on the right side i found a easy and simple way. The code is also easy to adapt for your needs or to develop.

If you use and adapt the code, please post your solution in the comment line. Maybe it will expand and i could develop a universal archive plugin.