Jump to content

pagination by date


sakkoulas
 Share

Recommended Posts

hi people

can anyone tell me some tips to paginate by date.
i want to show todays day posts, and have two links with next day and before day.
i can't figure how to check if there are posts from past dates.
thanks

Link to comment
Share on other sites

I'm a little bit ashamed for my code but ok :-[

$today = date('Y-m-d');
$dayBefore =  date("Y m, d", strtotime("yesterday"));
echo "today: $today </br>";
echo "lastdate $dayBefore </br>";
$results = $pages->find("sort=-publish_from, categories=$page,publish_from>=$today");
 foreach ($results as $result) {
 	echo "$result->title </br>";
 }
 
$next = $results->getNext($result); 
$prev = $results->getPrev($result); 

if($prev) echo "<a href='$prev->url'>Prev</a> ";
if($next) echo "<a href='$next->url'>Next</a> ";


 

Link to comment
Share on other sites

There's million ways to, but I think you first need to make clear what url you'll need to display the post of today or any day when you go next or previous day.

I don't know the blog profile much. How is the category the $page? Are you on a category page when you want this to display?

I don't think prev() next() will work here.

I think best is you would use url segments, so you would have like /posts/today, /posts/dd-mm-yyyy

But where is the category coming from then?

Link to comment
Share on other sites

Posting code to github gist... 

Much easier here is the code: 

https://gist.github.com/somatonic/5067314

Something to start with and think about , not really tested and sure about the date to compare with publish_from=$prevday

as those will be timestamps, but you could convert them first.

Just tested a little around and cleaned up script and added comments.

  • Like 1
Link to comment
Share on other sites

yes i am on a category page
from other sites i can see they use /posts/today,  and /posts/dd-mm-yyyy for other pages so i think this is the way
i use url segments i have a pagination there for test purposes
 

ok i'll try with this, thanks soma

Link to comment
Share on other sites

I created another version to show how to create this navigation with post which have a date with daytime. So it covers a range of 24 hours and not only a date without time.

It looks for the next post found in future and past, so it will still work if there's a day in between where no posts are published.

I created a new gist snippet for anyone interested as reference:

https://gist.github.com/somatonic/5068777

It will give you something like this

post-100-0-45898400-1362181222_thumb.png

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...