1

I'm pretty lost... I'm hoping someone can lead me onto the right track!

I'm trying to achieve the effect of a post timeline, by paginating the posts (1 per page) and rather than displaying the pages as numbered (i.e. 1, 2, 3, etc), I want to display the links as the date of each post, like this:

LATEST << | 3 Mar | 15 Feb | 22 Jan | 17 Dec | >> OLDEST

So far, I've looked at the built-in Wordpress functions 'get_pagination' and 'paginate_links', but I'm really struggling!

Any help would be most appreciated. Thank you!

2 Answers 2

1

Looks like you asked this question elsewhere,

For reference:

<?php
echo '<ul id="timeline">';
echo '<li>Latest</li>';
$prev_month = '';
$prev_year = '';
$args = array(
         'posts_per_page' => 10,
         'ignore_sticky_posts' => 1
);
$postsbymonth = new WP_Query($args);
while($postsbymonth->have_posts()) {
    $postsbymonth->the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_time('j'); ?></a></li>
<?php
    if(get_the_time('F') != $prev_month || get_the_time('Y') != $prev_year && get_the_time('Y') == $prev_limit_year) {
        echo "<li>< ".get_the_time('M')."</li>\n";
    }
    $prev_month = get_the_time('F');
    $prev_year = get_the_time('Y');

}
echo '</ul>';
?>

I do not claim this works but I will assume the original author tested this before providing his answer, if his personal website is anything to go by.

1
  • 1
    I changed the focus of my question here because the above code doesn't behave in the same way as the paging functions, which account for the current page being viewed and adjust the range of pages visible on each side...
    – Amal
    Apr 30, 2012 at 4:08
0

I think I've managed to accomplish the timeline effect by using get_posts within this pagination function by Kriesi.

The main core of the code is in in my functions.php and I'm calling the function in the single template like this: kriesi_pagination($additional_loop->max_num_pages);

function kriesi_pagination($pages = '', $range = 3) {
       global $post;  
           $showitems = ($range * 2)+1;  
           global $paged;
           if(empty($paged)) $paged = 1;
            if($pages == '') {
                   global $wp_query;
                   $pages = $wp_query->max_num_pages;
                        if(!$pages) {
                      $pages = 1;
                        }
            }
        if(1 != $pages) {
            echo "<div class='pagination'><ul id='post-timeline'>";
            if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
            if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";
    $args = array( 'numberposts' => $pages, 'post_status'=> 'publish' );
    $myposts = get_posts( $args );
            for ($i=1; $i <= $pages; $i++) {
           $p = $i-1;
           $entryDay = date('j', strtotime($myposts[$p]->post_date));
           $entryMon = date('M', strtotime($myposts[$p]->post_date));
           //$newID = $myposts[$p]->post_date('j,M');
                   if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {

                    echo ($paged == $i)? "<li class='current'><span class='day'>".$entryDay."</span><br/><span class='small'>".$entryMon."</span></li>":"<li class='timeline'><a href='".get_pagenum_link($i)."' class='inactive' ><span class='day'>".$entryDay."</span><br/><span class='small'>".$entryMon."</span></a></li>"; 
                   }
            }
           if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";  
           if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
           echo "</ul></div>\n";
           }
    }

If anyone has any feedback about this code - whether it's okay to use get_posts alongside the for loop in this way, or if there is a better way to do it - please let me know!

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.