• Resolved Joke De Winter

    (@dewinter)


    Hi,

    I am trying to display an archive along this format:

    May 2010
    07.05.10 – Post title

    April 2010
    29.04.10 – Post title
    23.04.10 – Post title

    Using the wp_get_archives() thing makes me choose between either by month or post-by-post. Is there a way to combine them?
    I would prefer not to use a plugin, but if that is the only way to do it, then point me in the right direction.

    Many thanks in advance.

    Jo

Viewing 1 replies (of 1 total)
  • Thread Starter Joke De Winter

    (@dewinter)

    I found a solution myself. Based on this thread: https://www.ads-software.com/support/topic/291728?replies=10.

    Here is my solution:

    <?php // Variables $month, $prevmonth, $year and $prevyear are used to section the archive display ?>
    <?php 	$month = '';
    		$prevmonth = '';
    		$year = '';
    		$prevyear = ''; ?>
    
    <?php // Cycle through all the posts to display the archive ?>
    <?php query_posts('showposts=-1'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<?php // Find the month/year of the current post ?>
    	<?php $year = mysql2date('Y', $post->post_date); ?>
    	<?php $month = mysql2date('F', $post->post_date); ?>
    
    	<?php // Compare the current month with the $prevmonth ?>
    	<?php if ($month != $prevmonth) { ?>
    		<?php // If it is different, display the new month and reset $prevmonth ?>
    		<h4><?php echo $month . ' ' . $year; ?></h4>
    		<?php $prevmonth = $month; ?>
    
    	<?php // In case the previous post was a year ago in the same month ?>
    	<?php } elseif ($year != $prevyear) { ?>
    		<h4><?php echo $month . ' ' . $year; ?></h4>
    		<?php $prevmonth = $month; ?>
    		<?php $prevyear = $year; ?>
    	<?php } ?>
    
    	<?php // Display the post in this month ?>
    	<p><a href="<?php the_permalink(); ?>"><?php echo mysql2date('d.m.y', $post->post_date); ?> - <?php the_title(); ?></a></p>
    
    <?php endwhile; endif; ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Display archive by month and then post-by-post?’ is closed to new replies.