WordPress.org

Ready to get started?Download WordPress

Forums

Custom pagination (showing date instead of number) (2 posts)

  1. aneemal
    Member
    Posted 2 years ago #

    Hi all,

    I'm hoping this is possible, or if I'm wasting my time - please tell me!

    WordPress has a built-in pagination function. At the moment, I have modified my settings so that one post is published per page. Would it be possible to alter the code so that each 'page' displays as a date, rather than a number?

    function get_pagination($range = 4){
      //...
      if($max_page > $range){
          // When closer to the beginning
          if($paged < $range){
            for($i = 1; $i <= ($range + 1); $i++){
              echo "<a href='" . get_pagenum_link($i) ."'";
              if($i==$paged) echo "class='current'";
              echo ">$i</a>";
            }
          }
       }

    So, instead of echoing $i, is there a way to reference the postmeta data for each of the posts in this loop?

    So that the outcome would be something like this:

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

  2. bcworkz
    Member
    Posted 2 years ago #

    It's possible. Take a look at Function Reference/get adjacent post source. You will need to make your custom version of this that takes a post date as an argument instead of fetching the current post date.

    Your template can then get the adjacent posts, extract their dates, then get the posts adjacent to the adjacent posts, etc. Then assemble the link and date info from this resulting list of posts into the nav line that you envision.

    Cool idea, btw.

Topic Closed

This topic has been closed to new replies.

About this Topic