0

干草每个人都需要一点帮助,因为我是编码新手。

例如,每次数字更改时是否可以添加标题。

在我的节目页面上有剧集块,显示可用的季节和剧集,它们的基础是这样的

Season 1. Episode 1
Season 1. Episode 2
Season 1. Episode 3
Season 2. Episode 1
Season 2. Episode 2
Season 2. Episode 3

我想要做的是每次季节编号更改时添加一个标题,说明它是什么季节

第1季

Season 1. Episode 1
Season 1. Episode 2
Season 1. Episode 3

第2季

Season 2. Episode 1
Season 2. Episode 2
Season 2. Episode 3

谁能帮我实现这是我的代码。

        <ul class="col2">
        {foreach from=$episodes key=id item=val name=episode_loop}
        <li>
                <h5 class="episode_item">
                    {if $global_settings.seo_links}
                        <a class="link" href="{$baseurl}/{$routes.show}/{$val.perma}/season/{$val.season}/episode/{$val.episode}" title="{$lang.show_episode_title|replace:'#season#':$val.season|replace:'#episode#':$val.episode}">{$lang.show_episode_title|replace:'#season#':$val.season|replace:'#episode#':$val.episode}</a>
                    {else}
                        <a class="link" href="{$baseurl}/index.php?menu=episode&perma={$val.perma}&season={$val.season}&episode={$val.episode}" title="{$lang.show_episode_title|replace:'#season#':$val.season|replace:'#episode#':$val.episode}">{$lang.show_episode_title|replace:'#season#':$val.season|replace:'#episode#':$val.episode}</a>
                    {/if}
                </h5>
        </li>
            {if $smarty.foreach.episode_loop.iteration % 4 eq 0}<div class="clear"></div>{/if}
        {/foreach}
    </ul>

请有人帮助我

谢谢

4

3 回答 3

0

感谢您的回答,但他们没有工作,但我解决了它添加这个

{if $val.episode eq 1}
   <h2>Season {$val.season}</h2>
        {/if}
            <li>
                <h5 class="episode_item">
                    {if $global_settings.seo_links}
                        <a class="link" href="{$baseurl}/{$routes.show}/{$val.perma}/season/{$val.season}/episode/{$val.episode}" title="{$lang.show_episode_title|replace:'#season#':$val.season|replace:'#episode#':$val.episode}">Episode {$val.episode}{if $val.episodetitle} <span class="tv_episode_name"> - {$val.episodetitle}</span>{/if}</a>
                    {else}
                        <a class="link" href="{$baseurl}/index.php?menu=episode&perma={$val.perma}&season={$val.season}&episode={$val.episode}" title="{$lang.show_episode_title|replace:'#season#':$val.season|replace:'#episode#':$val.episode}">{$lang.show_episode_title|replace:'#season#':$val.season|replace:'#episode#':$val.episode}</a>
                    {/if}
                </h5>
        </li>
于 2013-08-16T07:36:19.227 回答
0

我不是 100% 确定如何使用这个模板引擎来做到这一点,但使用常规 PHP 你可以做类似的事情

$currentSeason = 0;
foreach( $episodes as $key => $val )
{
    if( $val['season'] != $currentSeason )
    {
        .. Show Title ....
        $currentSeason = $val['season'];
    }

    ... Show rest of information ....
}
于 2013-08-15T11:26:40.820 回答
0

像这样的东西。存储当前季节,并在每次更改时输出标题。我不知道您的数据是什么样的,因此您可能需要调整检查和打印输出,但这应该可以让您到达那里(第 3-6 行)。

<ul class="col2">
    {foreach from=$episodes key=id item=val name=episode_loop}
        {if $currentSeason != $val.season}
            PUT YOUR SEASON TITLE HERE
            {$currentSeason=$val.season}
        {/if}
        <li>
            <h5 class="episode_item">
                {if $global_settings.seo_links}
                    <a class="link" href="{$baseurl}/{$routes.show}/{$val.perma}/season/{$val.season}/episode/{$val.episode}" title="{$lang.show_episode_title|replace:'#season#':$val.season|replace:'#episode#':$val.episode}">{$lang.show_episode_title|replace:'#season#':$val.season|replace:'#episode#':$val.episode}</a>
                {else}
                    <a class="link" href="{$baseurl}/index.php?menu=episode&perma={$val.perma}&season={$val.season}&episode={$val.episode}" title="{$lang.show_episode_title|replace:'#season#':$val.season|replace:'#episode#':$val.episode}">{$lang.show_episode_title|replace:'#season#':$val.season|replace:'#episode#':$val.episode}</a>
                {/if}
            </h5>
        </li>
        {if $smarty.foreach.episode_loop.iteration % 4 eq 0}<div class="clear"></div>{/if}
    {/foreach}
</ul>
于 2013-08-15T11:26:46.133 回答