uuragoda Posted June 29, 2015 Share Posted June 29, 2015 Hi, Im new to processwire and the website I have this problem with was build by a third party company. I have some problems with displaying page items on the homepage with the script below. Heres the story; I have a Newspage and I have listed about 20 news articles on this page. Link to news page : http://dev2.aot.com.au/about/newsroom/ I have a 'chunk' script calling these news articles and displaying on the home page with the script below. http://dev2.aot.com.au/ <?php $items = $page->find("parent=/about/newsroom, limit=12"); $numItems = count($items); $numPerContainer = 12; $itemx = 0; foreach($items as $newsItem): ?> <?php if ($itemx % $numPerContainer === 0):?> <div id="car-dis" class="outer owl-carousel"> <?php endif; ?> <div class="news-item"> <span class="news-date"><?php echo $newsItem->get('news_date'); ?></span> <h3 class="news-title"><a href="<?php echo $newsItem->url; ?>"><?php echo $newsItem->title; ?></a></h3> <p><?php echo $newsItem->news_introtext; ?>...</p><p><a class="post-cta" href="<?php echo $newsItem->url; ?>">READ MORE</a></p> </div> <?php if ($itemx % $numPerContainer === 11 || $itemx === $numItems): ?> </div> <?php endif; ?> <?php $itemx++; endforeach; ?> The problem is, the home ppge news items doesn't show the latest 2 items I added recently. Does anyone know why? Link to comment Share on other sites More sharing options...
Wanze Posted June 29, 2015 Share Posted June 29, 2015 Hi uuragoda, Welcome to the World of ProcessWire, enjoy! Now to your question: You are limiting the number of news entries to twelfe. Could it be the case that there are more than 12 items? Maybe you're just missing sorting the news entries, e.g. by a date field or by the native created field: $items = $pages->find("parent=/about/newsroom, limit=12, sort=-created"); // Get the latest news by created date, descendant sorting 1 Link to comment Share on other sites More sharing options...
uuragoda Posted June 29, 2015 Author Share Posted June 29, 2015 Hi @Wanze, we are getting there. sort=-created got my articles displaying. But how do I sort it by date? I tried $items = $page->find("parent=/about/newsroom, limit=12, sort=-date"); But it doesnt seem to do anything. Link to comment Share on other sites More sharing options...
Wanze Posted June 29, 2015 Share Posted June 29, 2015 Does your news template have a datetime field called "date" assigned? Maybe you named it differently? 1 Link to comment Share on other sites More sharing options...
uuragoda Posted June 29, 2015 Author Share Posted June 29, 2015 Sweet! yes my date field is called news_date. Thanks again. Processwire looks interesting. Thanks again for your quick response. 3 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