如何将每个表格行的单元格数量限制为 3?
我有一个动态填充的表格,我想将其中的列数限制为 3,以便下一个 td
星号出现在下一行。 (请参阅 http://kbay.in 并检查页面顶部的类别按钮。)
以下是我导入使用 Smarty PHP 的数据:
<table cellpadding="0" cellspacing="4" width="100"; border-collapse="collapse";>
<tr>
{foreach from=$array_categories item=v name=cat}
<td valign="top" width="116px" align="left">
{capture name=some_content assign=categ_url}
{if $v.subcats>0}{$live_site}/{if $seo_settings.enable_mod_rewrite}{$v.id}-{$v.url_title}/1/listings.html{else}listings.php?category={$v.id}{/if}{/if}
{/capture}
<a href="{$categ_url}">{$v.name|escape:"html"}{if $appearance.categ_count_ads} ({$v.ads}) {/if}</a>
{/foreach}</td></tr> </table>
如何使每行中只有 3 个表格单元格?
I have a dynamically filled table, in which I would like to limit the number of columns to 3, so that the next td
stars on the next line. (See http://kbay.in and check the categories button at the top of the page.)
Here's how I import the data using Smarty PHP:
<table cellpadding="0" cellspacing="4" width="100"; border-collapse="collapse";>
<tr>
{foreach from=$array_categories item=v name=cat}
<td valign="top" width="116px" align="left">
{capture name=some_content assign=categ_url}
{if $v.subcats>0}{$live_site}/{if $seo_settings.enable_mod_rewrite}{$v.id}-{$v.url_title}/1/listings.html{else}listings.php?category={$v.id}{/if}{/if}
{/capture}
<a href="{$categ_url}">{$v.name|escape:"html"}{if $appearance.categ_count_ads} ({$v.ads}) {/if}</a>
{/foreach}</td></tr> </table>
How can I make it so that there are only 3 table cells in each row?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
迭代
<foreach
循环的/a>属性:$smarty.foreach.cat.iteration
是Smarty2语法,如果你使用Smarty3也可以使用$v@iteration< /代码>。
Use the
iteration
property offoreach
loop:$smarty.foreach.cat.iteration
is Smarty2 syntax, if you use Smarty3 you can also use$v@iteration
.每次在循环中增加一个计数器,并在循环中进行检查,必要时开始新行。像这样的东西:
increment a counter each time in the loop and do a check within your loop starting a new row when necessary. Something like: