• Resolved tida19

    (@tida19)


    According to this post
    https://www.ads-software.com/support/topic/display-archive-by-month-and-then-post-by-post

    I’ve been trying to show archive like:
    January 2012
    dd.mm.yy – post
    dd.mm.yy – post

    February 2012
    dd.mm.yy – post
    dd.mm.yy – post

    But it shows like always have one post of the current month and repeat current month below

    October 2012
    03.10.2012 – post

    October 2012
    02.10.2012 – post
    01.10.2012 – post

    here is the code please help me try to fix it

    <?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 ?>
    		<br/><br/><h3><?php echo $month . ' ' . $year; ?></h3><br/>
    		<?php $prevmonth = $month; ?>
    
    	<?php // In case the previous post was a year ago in the same month ?>
    	<?php } elseif ($year != $prevyear) { ?>
    		<h3><?php echo $month . ' ' . $year; ?></h3>
    		<?php $prevmonth = $month; ?>
    		<?php $prevyear = $year; ?>
    	<?php } ?>
    
    	<?php // Display the post in this month ?>
    	<p ><a class="list_archive" href="<?php the_permalink(); ?>"><?php echo mysql2date('d.m.y', $post->post_date); ?> - <?php the_title(); ?></a></p>
    <?php endwhile; endif; ?>
    <br/>
Viewing 2 replies - 1 through 2 (of 2 total)
  • I believe that you need to set $prevyear at the same time you set $prevmonth. Try changing this:

    <?php if ($month != $prevmonth) { ?>
    		<?php // If it is different, display the new month and reset $prevmonth ?>
    		<br/><br/><h3><?php echo $month . ' ' . $year; ?></h3><br/>
    		<?php $prevmonth = $month; ?>

    to this:

    <?php if ($month != $prevmonth) { ?>
    		<?php // If it is different, display the new month and reset $prevmonth ?>
    		<br/><br/><h3><?php echo $month . ' ' . $year; ?></h3><br/>
    		<?php $prevmonth = $month; ?>
    		<?php $prevyear = $year; ?>
    Thread Starter tida19

    (@tida19)

    All right! it works well ??

    Thank you so much I looked over it

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Archive page listed monthly – but I have one problem’ is closed to new replies.