|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ShamusMay Smarty Rookie
Joined: 28 Apr 2015 Posts: 18
|
Posted: Thu May 19, 2016 3:11 pm Post subject: Limit Foreach Results within a Section Loop |
|
|
I have a piece of code for my article section that returns the Topic and all Articles associated to that topic. I want to limit the number of articles displayed to only 3 per topic. How can I achieve this?
*I tried using an iteration and break, but it only would show 3 articles on 1 topic.
Code: | {section name=TopicsList loop=$TopicsList}
<p>{$TopicsList[TopicsList].topic_name}</p>
{foreach $ArticlesList as $i}
{if $i.article_topic_id == $TopicsList[TopicsList].topic_id}
<p>{$i.article_title}</p>
{/if}
{/foreach} |
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu May 19, 2016 7:04 pm Post subject: |
|
|
Why you pass more than 3 articles to the template to begin with? |
|
Back to top |
|
ShamusMay Smarty Rookie
Joined: 28 Apr 2015 Posts: 18
|
Posted: Thu May 19, 2016 7:16 pm Post subject: |
|
|
I guess it is just a grab everything function.
Code: | function getArticlesList() {
return
getSqlResult(
"select * from article order by article_topic_id, article_title",
SQL_RESULT_ALL);
} |
I used to just show all articles, but the article list is getting too big, so I need to limit it now. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu May 19, 2016 8:41 pm Post subject: |
|
|
Then fix your PHP code, instead of wasting time trying to do everything in a template.
Next time you'd ask Smarty to make coffee and bake cookies at this rate. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|