简体   繁体   English

Smarty .TPL文件的问题

[英]Issues with .TPL file with Smarty

I use PHP Melody on my site and I don't know how can I make one thing. 我在网站上使用PHP Melody,但我不知道该怎么做。

I have this code to print on index 30 post: 我有此代码可在索引30上打印:

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" ) 我需要在5个帖子后放置divdiv 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? PS:.tpl文件是否已过时以至于不再适用于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: 为了避免在每个循环上进行索引检查,请使用array_chunk将数组拆分为更小的块,其中包含所需的确切项目数:

{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}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM