每次添加标题数字更改

时间:2013-08-15 10:57:59

标签: php html smarty

干草每个人都需要帮助,因为我不熟悉编码。

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

在我的节目页面上有一个剧集,显示可用的季节和剧集,它们基于这样的

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>

请有人帮助我

感谢

3 个答案:

答案 0 :(得分:0)

我不是100%确定如何使用此模板引擎,但使用常规PHP,您可以执行类似

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

    ... Show rest of information ....
}

答案 1 :(得分: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>

答案 2 :(得分: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>