leoric Posted October 18, 2013 Share Posted October 18, 2013 <?php $matches=$pages->find("parent_id=$page->id, limit=5,sort=-id"); $pagination = $matches->renderPager(); echo $pagination; echo '<ul class=rows>'; foreach($matches as $item) { echo '<li><a href="'.$item->url.'">'.$item->title.'</a></li>'; } echo '</ul>'; echo $pagination; ?> hi , this is my code , the problem is "sort=-id" isnot working this is some articles in many pages. when i use "$matches=$pages->find("parent_id=$page->id, limit=5)->sort("-id");" then i found the articles order by -id in current page,but i want to them work in all of the pages. and if i use "sort=-title/title" replace "sort=id/-id" ,its working perfect. whats wrong with this? thank you ! Link to comment Share on other sites More sharing options...
adrian Posted October 18, 2013 Share Posted October 18, 2013 Maybe I am not following what you need exactly, but I think this might work for you: $matches = $page->children("limit=5,sort=-id"); Link to comment Share on other sites More sharing options...
teppo Posted October 18, 2013 Share Posted October 18, 2013 I'm also having problems following your question; the part about finding articles "in current page" vs. "in all of the pages" confuses me, as you've specified in your selector that you only want articles with current page as their parent. Obviously you'll only find articles below current page this way (and the syntax Adrian suggested is more straightforward way to achieve the same.) Anyway, that aside, I can't seem to reproduce your issue either. Sorting by id/-id provides results in opposite order, which kind of signals that those work as intended. What kind of results are you getting, ie. how did you realize that sort=id/-id doesn't work? Link to comment Share on other sites More sharing options...
leoric Posted October 18, 2013 Author Share Posted October 18, 2013 Maybe I am not following what you need exactly, but I think this might work for you: $matches = $page->children("limit=5,sort=-id"); thank you for you reply,adrian in the fact,i try do this earlier,but the problem is still Link to comment Share on other sites More sharing options...
adrian Posted October 18, 2013 Share Posted October 18, 2013 Oh I think I see - "all of the pages" means across all paginated results pages - correct? That should still work and it is strange that it is working with -title for you. What happens if you use: sort=-sort Link to comment Share on other sites More sharing options...
leoric Posted October 18, 2013 Author Share Posted October 18, 2013 @adrian @teppo i am sorry for my expression is not clear. and i want to do like this article id: 1 2 3 4 5 6 7 8 9 10 11 12 ... page 1 12 11 10 9 page 2 8 7 6 5 page 3 4 3 2 1 ... but when i use this code "$matches=$pages->find("parent_id=$page->id, limit=5,sort=-id");" or "$matches = $page->children("limit=5,sort=-id");" its not working.. if i use "$matches=$pages->find("parent_id=$page->id, limit=5")->sort("-id")"; the result will be this: article id: 1 2 3 4 5 6 7 8 9 10 11 12 ... page 1 4 3 2 1 page 2 8 7 6 5 page 3 12 11 10 9 ... Link to comment Share on other sites More sharing options...
adrian Posted October 18, 2013 Share Posted October 18, 2013 Thanks for the details explanation - the behavior you are seeing when using ->sort("-id") is expected and working as intended. I don't really understand why the other approach is not working as it should. I am not sure how you are comparing the output titles to the IDs, so maybe just to be sure can you try: echo '<li><a href="'.$item->url.'">'.$item->title.' ('.$item->id.')</a></li>'; Just in case the your expected order is not actually based on the ID, but rather on your manually sorted order. Which is also why I suggested the -sort option. Sorry if you do have this right - sometimes it can be easy to overlook the simplest things. Maybe also try the selector in the selector test module which will output all the information about each page, including the ID. Link to comment Share on other sites More sharing options...
leoric Posted October 18, 2013 Author Share Posted October 18, 2013 Thanks for the details explanation - the behavior you are seeing when using ->sort("-id") is expected and working as intended. I don't really understand why the other approach is not working as it should. I am not sure how you are comparing the output titles to the IDs, so maybe just to be sure can you try: echo '<li><a href="'.$item->url.'">'.$item->title.' ('.$item->id.')</a></li>'; Just in case the your expected order is not actually based on the ID, but rather on your manually sorted order. Which is also why I suggested the -sort option. Sorry if you do have this right - sometimes it can be easy to overlook the simplest things. Maybe also try the selector in the selector test module which will output all the information about each page, including the ID. i am back... omg,its working i dont changed something,just do as you say : add "$item->id" then i found its work correctly its a big joke,i think if the cache caused? my work space in localhost (appserv + win7 x64) @adrian thank you very much! 1 Link to comment Share on other sites More sharing options...
ryan Posted October 20, 2013 Share Posted October 20, 2013 I'm not sure what the value of sorting by "id" is, but if it's for chronological reasons, consider using "created" instead as your sort field. That's going to be more reliable to achieve the same purpose. 2 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted October 21, 2013 Share Posted October 21, 2013 Agree with Ryan. If it is an article consider a custum date field in your template, default to current date. ( so editors don't have to do anything, unless they want to) Then the sort can use that date. That date is manipulatable. 1 Link to comment Share on other sites More sharing options...
kongondo Posted May 18, 2014 Share Posted May 18, 2014 I'm not sure what the value of sorting by "id" is, but if it's for chronological reasons, consider using "created" instead as your sort field. That's going to be more reliable to achieve the same purpose. Reviving this old topic.... For pages created in bulk using the API, many will have the same timestamp (e.g. batch create 1000 pages using the API); the only unique thing for such pages will be the ID. If I limit my selector to one template only, the ID then becomes a more reliable get selector to use with < or >. The assumption here is that since IDs are incremented, a greater ID denotes a later created time. In bulk page creation then, the timestamp is less reliable and will return the same result every time which is of no good use when creating next/prev links ...maybe I'm missing something? 3 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted May 18, 2014 Share Posted May 18, 2014 good point @kongondo ! Link to comment Share on other sites More sharing options...
Pete Posted May 18, 2014 Share Posted May 18, 2014 I tend to sort by created then by id in this case. Or if you're using the API to import something then overwrite the created time (can't remember if you can do that but certainly you can use another field). Link to comment Share on other sites More sharing options...
bwakad Posted May 18, 2014 Share Posted May 18, 2014 this is also working: sort={$page->id} 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