I use PHP Melody on my site and I don't know how can I make one thing.
I have this code to print on index 30 post:
Code:
{get_advanced_video_list assignto="new_videos" limit="30"}
{foreach from=$new_videos key=k item=video_data}
I need after 5 post to put a div
( div class="thumb-holder"
)
So there should be:
>div class="thumb-holder" post 1 post 2 post 3 post 4 post 5 /div><br>
>div class="thumb-holder" post6 post7 post8 post9 post10 /div><br>
>div class="thumb-holder" post11 post12 post13 post14 post15 /div><br>
>.........................<br>
>div class="thumb-holder" post26 post27 post28 post29 post30 /div <br>
I tried more things, but nothing has worked. What can I do?
PS: Is a .tpl file so outdated that it no longer works with PHP?
{foreach from=$entries key=i item=topic name=foo}
{if $smarty.foreach.foo.index == 10}
{break}
{/if}
{if $topic.topic_style == question}
<li>
<a href="topic.php?id={$topic.id}">{$topic.title}</a>
</li>
{/if}
{/foreach}
Here exactly what you wish:
<div class="thumb-holder">
{foreach from=$new_videos key=k item=video_data name=foo}
{if $smarty.foreach.foo.index > 1 and $smarty.foreach.foo.index is div by 5}
</div>
<hr>
<div class="thumb-holder">
{/if}
{$video_data}<br>
{/foreach}
</div>
To avoid index checking on every loop, use array_chunk to split your array into smaller chunks with exact amount of items you need:
{assign var=video_groups value=$new_videos|array_chunk:5:true}
{foreach from=$video_groups item=video_group}
<div class="thumb-holder">
{foreach from=$video_group item=video_data key=k}
<img id="{$k}" src="{$video_data}" />
{/foreach}
</div>
{/foreach}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.