如何实现foreach横排偱环 [技术论坛 - 使用问答] imag1

正在浏览:   1 名游客






如何实现foreach横排偱环
资深会员
注册日期:
2004/12/5 19:34
来自 308627538
所属群组:
注册会员
帖子: 210 | 精华: 4
等级: 13; EXP: 52
HP: 0 / 313
MP: 70 / 2677
离线

<table>
<
tr>
  <{foreach 
item=mp3files from=$block.debaser_files name=foo }>
    <
td>
 
    <
a href="(script removed)openWithSelfMain('<{$xoops_url}>/modules/debaser/player.php?id=<{$mp3files.id}>','player',10,10)" <{if $mp3files.usetooltips == true}>onmouseover="ddrivetip('<{if $mp3files.album > 0 || $mp3files.album != ''}><{$smarty.const._MB_DEBASER_ALBUM}> <{$mp3files.album}><br /><{/if}><{if $mp3files.year > 0}><{$smarty.const._MB_DEBASER_YEAR}> <{$mp3files.year}><br /><{/if}><{if $mp3files.addinfo > 0}><{$smarty.const._MB_DEBASER_COMMENT}> <{$mp3files.addinfo}><br /><{/if}><{if $mp3files.track > 0}><{$smarty.const._MB_DEBASER_TRACK}> <{$mp3files.track}><br /><{/if}><{$smarty.const._MB_DEBASER_LENGTH}> <{$mp3files.length}><br /><{$smarty.const._MB_DEBASER_BITRATE}> <{$mp3files.bitrate}><br /><{$smarty.const._MB_DEBASER_FREQUENCY}> <{$mp3files.frequence}>','lightgrey', 200);" onmouseout="hideddrivetip()"<{/if}>><{$mp3files.artist}> - <{$mp3files.title}></a>
    </
td>
<{if 
$smarty.section.foo.iteration is not odd by 2}>
    </
tr>
    <
tr>
    <{/if}>

  <{/foreach}>
</
tr>
</
table>

我加了个

<{if $smarty.section.foo.iteration is not odd by 2}>
    </
tr>
    <
tr>
还是无法实现那个效果,请帮我看看是不是代码有错误

10/15 12:19
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: 如何实现foreach横排偱环
网站管理员
注册日期:
2005/10/29 13:32
来自 北京
所属群组:
网站管理员
注册会员
ComSupp
推广组
帖子: 1837 | 精华: 12
等级: 35; EXP: 77
HP: 347 / 869
MP: 612 / 5153
离线
参考article的template实现方法。

10/15 12:25
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: 如何实现foreach横排偱环
Support Team
注册日期:
2005/4/30 13:09
来自 安徽安庆
所属群组:
注册会员
ComSupp
帖子: 375 | 精华: 3
等级: 18; EXP: 5
HP: 0 / 426
MP: 125 / 3148
离线

<table
<
tr
<{
assign var="counter" value=0}>
  <{foreach 
item=mp3files from=$block.debaser_files}> 
  <{
assign var="counter" value="`$counter+1`"}>
<{if 
$counter%== 0}>
    <
td
    <
a href="(script removed)openWithSelfMain('<{$xoops_url}>/modules/debaser/player.php?id=<{$mp3files.id}>','player',10,10)" <{if $mp3files.usetooltips == true}>onmouseover="ddrivetip('<{if $mp3files.album > 0 || $mp3files.album != ''}><{$smarty.const._MB_DEBASER_ALBUM}> <{$mp3files.album}><br /><{/if}><{if $mp3files.year > 0}><{$smarty.const._MB_DEBASER_YEAR}> <{$mp3files.year}><br /><{/if}><{if $mp3files.addinfo > 0}><{$smarty.const._MB_DEBASER_COMMENT}> <{$mp3files.addinfo}><br /><{/if}><{if $mp3files.track > 0}><{$smarty.const._MB_DEBASER_TRACK}> <{$mp3files.track}><br /><{/if}><{$smarty.const._MB_DEBASER_LENGTH}> <{$mp3files.length}><br /><{$smarty.const._MB_DEBASER_BITRATE}> <{$mp3files.bitrate}><br /><{$smarty.const._MB_DEBASER_FREQUENCY}> <{$mp3files.frequence}>','lightgrey', 200);" onmouseout="hideddrivetip()"<{/if}>><{$mp3files.artist}> - <{$mp3files.title}></a
    </
td
    </
tr
    <
tr
<{else}>
<
td
    <
a href="(script removed)openWithSelfMain('<{$xoops_url}>/modules/debaser/player.php?id=<{$mp3files.id}>','player',10,10)" <{if $mp3files.usetooltips == true}>onmouseover="ddrivetip('<{if $mp3files.album > 0 || $mp3files.album != ''}><{$smarty.const._MB_DEBASER_ALBUM}> <{$mp3files.album}><br /><{/if}><{if $mp3files.year > 0}><{$smarty.const._MB_DEBASER_YEAR}> <{$mp3files.year}><br /><{/if}><{if $mp3files.addinfo > 0}><{$smarty.const._MB_DEBASER_COMMENT}> <{$mp3files.addinfo}><br /><{/if}><{if $mp3files.track > 0}><{$smarty.const._MB_DEBASER_TRACK}> <{$mp3files.track}><br /><{/if}><{$smarty.const._MB_DEBASER_LENGTH}> <{$mp3files.length}><br /><{$smarty.const._MB_DEBASER_BITRATE}> <{$mp3files.bitrate}><br /><{$smarty.const._MB_DEBASER_FREQUENCY}> <{$mp3files.frequence}>','lightgrey', 200);" onmouseout="hideddrivetip()"<{/if}>><{$mp3files.artist}> - <{$mp3files.title}></a
    </
td
    <{/if}> 
  <{/foreach}> 
  <
td>
</
td>
</
tr
</
table>



"<{if $counter%2 == 0}> "2可以改成横排数字

10/15 13:35
_________________
绿野info
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: 如何实现foreach横排偱环
资深会员
注册日期:
2004/12/5 19:34
来自 308627538
所属群组:
注册会员
帖子: 210 | 精华: 4
等级: 13; EXP: 52
HP: 0 / 313
MP: 70 / 2677
离线
谢谢你给上这么详细的代码,我按你的代码成功了.哈哈,我会好好研究一下的.

10/16 0:52
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: 如何实现foreach横排偱环
网站管理员
注册日期:
2005/10/29 13:32
来自 北京
所属群组:
网站管理员
注册会员
ComSupp
推广组
帖子: 1837 | 精华: 12
等级: 35; EXP: 77
HP: 347 / 869
MP: 612 / 5153
离线
agl的代码有点复杂了,无需另外定义counter, foreach自身就有这个功能,$smarty.section.foo.iteration,除了iteration外,还可以使用first,last,show,total。

10/16 7:15
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: 如何实现foreach横排偱环
Support Team
注册日期:
2005/9/29 15:24
来自 广东顺德
所属群组:
注册会员
技术文档组
Dev+Hack
帖子: 358 | 精华: 3
等级: 17; EXP: 65
HP: 0 / 416
MP: 119 / 2568
离线
我的实现


<table>
    <
tr>
    <{foreach 
item=image from=$image_list name=image_list}>
        <
td>
        
这里放内容
        
</td>
        
    <{if 
$smarty.foreach.image_list.iteration $image_list_col_num eq 0}>
        </
tr><tr>
    <{elseif 
$smarty.foreach.image_list.last}>
        </
tr>
    <{/if}>
            
    <{
foreachelse}>
        <
td><p>提示没有项目</p></td>
    <{/foreach}>
    </
tr>        
</
table>

10/16 9:25
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: 如何实现foreach横排偱环
资深会员
注册日期:
2004/12/5 19:34
来自 308627538
所属群组:
注册会员
帖子: 210 | 精华: 4
等级: 13; EXP: 52
HP: 0 / 313
MP: 70 / 2677
离线
我刚开始就是想使用

$smarty
.section.foo.iteration

但就是搞不出那样的效果,可能是我后面的条件设置错误吧.

10/17 10:55
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: 如何实现foreach横排偱环
新进会员
注册日期:
10/13 23:08
所属群组:
注册会员
帖子: 11
等级: 2; EXP: 12
HP: 0 / 28
MP: 3 / 6
离线
這是我的新聞模組隨機新聞裡頭的原文,我也是用不出橫列效果。
----------------------------------------------------

<table>
<
tr>
    <
td>
        <
ul>
        <{foreach 
item=news from=$block.stories}>
<!--            <
li>     -->
            <{if 
$block.sort=='counter'}>
              [<{
$news.hits}>]   
            <{elseif 
$block.sort=='published'}>  
<!--               [<{
$news.date}>]   -->
            <{else}>
               [<{
$news.rating}>]
            <{/if}>
        <!--    <{
$news.topic_title}> - -->
        <
a href="<{$xoops_url}>/modules/news/article.php?storyid=<{$news.id}>" <{$news.infotips}>><{$news.title}></a> <br /><{$news.teaser}>   <!-- </li> -->
        <{/foreach}>
        </
ul>
    </
td>
</
tr>
</
table>

------------------------------------------------------

10/18 20:16
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: 如何实现foreach横排偱环
Support Team
注册日期:
2005/4/30 13:09
来自 安徽安庆
所属群组:
注册会员
ComSupp
帖子: 375 | 精华: 3
等级: 18; EXP: 5
HP: 0 / 426
MP: 125 / 3148
离线
引文:

staminas 写道:
這是我的新聞模組隨機新聞裡頭的原文,我也是用不出橫列效果。
----------------------------------------------------

<table>
<
tr>
    <
td>
        <
ul>
        <{foreach 
item=news from=$block.stories}>
<!--            <
li>     -->
            <{if 
$block.sort=='counter'}>
              [<{
$news.hits}>]   
            <{elseif 
$block.sort=='published'}>  
<!--               [<{
$news.date}>]   -->
            <{else}>
               [<{
$news.rating}>]
            <{/if}>
        <!--    <{
$news.topic_title}> - -->
        <
a href="<{$xoops_url}>/modules/news/article.php?storyid=<{$news.id}>" <{$news.infotips}>><{$news.title}></a> <br /><{$news.teaser}>   <!-- </li> -->
        <{/foreach}>
        </
ul>
    </
td>
</
tr>
</
table>

------------------------------------------------------



你是准备用ul还是td 实现?用ul配合样式可能只能实现两列横排。

10/19 10:15
_________________
绿野info
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: 如何实现foreach横排偱环
新进会员
注册日期:
10/13 23:08
所属群组:
注册会员
帖子: 11
等级: 2; EXP: 12
HP: 0 / 28
MP: 3 / 6
离线
都可以,只要原本新增橫列功能可以正常的使用就好,因為我只要去後台新增超出2個橫列時,他就變延升很長,而無法新增成為第三列了。

10/19 17:09
工具箱 短消息 Email PDF 书签 打印 举报 回顶部





不可查看帖子。
不可发帖。
不可回复。
不可编辑自己的帖子。
不可删除自己的帖子。
不可发起投票调查。
不可在投票调查中投票。
不可上传附件。
不可不经审核直接发帖。
不可使用主题类别。
不可以使用HTML语法。
不可以使用签名档。

[高级搜索]