sakkoulas Posted March 1, 2013 Share Posted March 1, 2013 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 More sharing options...
Soma Posted March 1, 2013 Share Posted March 1, 2013 Examples? Any code yet? Paginate? Do you mean with pager? 1 | 2 | 3 ? Or simply with $page->prev() $page->next() ? Link to comment Share on other sites More sharing options...
sakkoulas Posted March 1, 2013 Author Share Posted March 1, 2013 hi soma no just $page->prev() and $page->next(); I have experimented with ryan code that i have found in forum Link to comment Share on other sites More sharing options...
Soma Posted March 1, 2013 Share Posted March 1, 2013 IT would help greatly to see a example what you want to archive exactly AND what the structure is you have with "posts". Link to comment Share on other sites More sharing options...
sakkoulas Posted March 1, 2013 Author Share Posted March 1, 2013 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 More sharing options...
sakkoulas Posted March 1, 2013 Author Share Posted March 1, 2013 i am using blog profile module so i have posts parent with post children and categories with category items Link to comment Share on other sites More sharing options...
Soma Posted March 1, 2013 Share Posted March 1, 2013 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 More sharing options...
Soma Posted March 1, 2013 Share Posted March 1, 2013 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. 1 Link to comment Share on other sites More sharing options...
sakkoulas Posted March 1, 2013 Author Share Posted March 1, 2013 yes i am on a category pagefrom other sites i can see they use /posts/today, and /posts/dd-mm-yyyy for other pages so i think this is the wayi 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 More sharing options...
Soma Posted March 1, 2013 Share Posted March 1, 2013 You'll have to adapt it to your situation and test it out, that's all I can do. Link to comment Share on other sites More sharing options...
sakkoulas Posted March 1, 2013 Author Share Posted March 1, 2013 ok, thanks a lot Link to comment Share on other sites More sharing options...
Soma Posted March 1, 2013 Share Posted March 1, 2013 Now tested and put the code on gist github: https://gist.github.com/somatonic/5067314 I have some minor correction and added comments, some improvement to show how to handle 404 and dates. Link to comment Share on other sites More sharing options...
Soma Posted March 1, 2013 Share Posted March 1, 2013 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 2 Link to comment Share on other sites More sharing options...
sakkoulas Posted March 2, 2013 Author Share Posted March 2, 2013 this is fantastic thanks again soma Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now