Wednesday, 4 March 2015

Wordpress Year Pagination.

We have used Page No pagination in WordPress like

[15] [14] [13] ... [1]

Likewise we can create the Year pagination for our archive post. OK use the below code to simply past in your archive list area under the pagination part.


<?php
$current_year= date('Y'); // this will the current year
$archive_year = get_the_time('Y'); // this will get the year of the archive list
$starting_year= "2006"; // this will be our starting year
?>

<ul class="SOME CLASS">
<?php if($archive_year < $current_year ) { ?>
<li><a href="<?php echo get_year_link( $archive_year+1 ); ?>"><i class="SOME CLASS"></i></a></li>
<?php } ?>
<?php if($archive_year == $current_year ) { ?>
<li><a href="<?php echo get_year_link( $archive_year ); ?>"><i class="SOME CLASS"></i></a></li>
<?php } ?>
<li class="SOME CLASS FOR DIVIDER"></li>
<?php

for($i=date('Y'); $i>2005; $i--) {
$diff= $i-$archive_year;
if($diff>2&&$diff<4)
{
echo '<li><a href='.get_year_link( $current_year ).'>'.$current_year.'</a></li>';
echo '<li><a class="SOME CLASS">…</a></li>';
}

if($diff>-3&&$diff<3)
{
if ($i == $archive_year) {
echo '<li class="active"><a href='.get_year_link( $i ).'>'.$archive_year.'</a></li>';
}
else {
echo '<li><a href='.get_year_link( $i ).'>'.$i.'</a></li>';
}
}

if($diff>-4&&$diff<-2)
{
echo '<li><a class="SOME CLASS">…</a></li>';
echo '<li><a href='.get_year_link( $starting_year ).'>'.$starting_year.'</a></li>';
}
}
?>
<li class="SOME CLASS FOR DIVIDER"></li>
<?php if($archive_year <= $current_year && $archive_year > '2006') { ?>
<li><a href="<?php echo get_year_link( $archive_year-1 ); ?>"><i class="SOME CLASS"></i></a></li>
<?php } ?>
<?php if($archive_year == $current_year && $archive_year == '2006') { ?>
<li><a href="<?php echo get_year_link( $archive_year); ?>"><i class="SOME CLASS"></i></a></li>
<?php } ?>
<?php if($archive_year != $current_year && $archive_year == '2006') { ?>
<li><a href="<?php echo get_year_link( $archive_year); ?>"><i class="SOME CLASS"></i></a></li>
<?php } ?>
</ul>


So the above will output like below


No comments:

Post a comment