mel47 Posted July 9, 2017 Share Posted July 9, 2017 Hi, I'm stuck on this issue for too much time now... I want to display a "new" badge beside the most recent pages. I don't have problem with the queries but I don't know how to display them: $news_member = $pages->find("template=news, body*=$page->title, publish_from>=$year, sort=-publish_from, limit=10"); $recentNews = $news_member->find("publish_from>=$lastMonth"); if ($news_member->count()) { foreach ($recentNews as $n1) { $content .= "<span class='tag is-success'>New</span><p><a href='{$n1->url}'>{$n1->title}</a></p>"; } foreach ($news_member as $n2) { $content .= "<p><a href='{$n2->url}'>{$n2->title}</a></p>"; } But, obviously, the list is repeated a second time by the second loop. How I can "substract" the recentNews from news_member? Or I'm on the wrong track? Thanks Mélanie Link to comment Share on other sites More sharing options...
kongondo Posted July 9, 2017 Share Posted July 9, 2017 (edited) Maybe something like this? $news_member = $pages->find("template=news, body*=$page->title, publish_from>=$year, sort=-publish_from, limit=10"); $content = ''; $newBadge = "<span class='tag is-success'>New</span>"; $lastMonth = 'SomeDate'; if ($news_member->count()) { foreach ($news_member as $n) { if($n->publish_from>=$lastMonth) $content .= $newBadge; $content .= "<p><a href='{$n->url}'>{$n->title}</a></p>"; } } Untested. Edited July 9, 2017 by kongondo 1 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