Adohgg Posted September 13, 2013 Posted September 13, 2013 function newsList(){    // Grab the page name from the url     $thisCategory = wire("page")->name;     // If the category is not called "news" then output the category name as a selector for the find.     if($thisCategory !="news") {         $category = "article_category.name=" . $thisCategory;     }        // Get the news posts - limited to ten for later pagination     $newsposts = wire("pages")->find("parent=/news-articles/, $category, template=TUT_news, limit=3");     $out =" ";     //Loop through the pages     foreach($newsposts as $newspost){         $out .="<div class='clearfix'>";         if($newspost->article_thumbnails){             $out .="<a href='{$newspost->article_thumbnails->url}' class=''>";             $out .="<img class='align_left' src='{$newspost->article_thumbnails->getThumb(listingthumb)}'>";             $out .="</a>";         }         $out .="<a href='{$newspost->url}'><h3>{$newspost->title}</h3></a>";         $out .="<p>{$newspost->article_introtext}</p>";         $out .="</div>";     }     echo $out; } I'm trying to use this code to get the most recent pages created and display them. I found this code on the wiki, but how would I make it display the most recent ones instead of the oldest ones?
adrian Posted September 14, 2013 Posted September 14, 2013 In the selector: $newsposts = wire("pages")->find("parent=/news-articles/, $category, template=TUT_news, limit=3"); you should just need to add: sort=-created eg: $newsposts = wire("pages")->find("parent=/news-articles/, $category, template=TUT_news, limit=3, sort=-created");Â That will sort your posts in reverse order (-) of created date/time.
Adohgg Posted September 14, 2013 Author Posted September 14, 2013 In the selector: $newsposts = wire("pages")->find("parent=/news-articles/, $category, template=TUT_news, limit=3"); you should just need to add: sort=-created eg: $newsposts = wire("pages")->find("parent=/news-articles/, $category, template=TUT_news, limit=3, sort=-created");Â That will sort your posts in reverse order (-) of created date/time. Worked like a charm. Thanks a lot!
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