应技术站长的需求,今天整理一下destoon在内容页批量调用所有自定义字段的方案:
以前是在内容模板中一个个的调用,确实有点繁琐,下面的方法就是批量循环出当前频道所有不为空的自定义字段内容。
我们在自定义函数api/extend.func.php文件中添加以下函数:
function xh_fileds_list($tb){
global $db;
$result = $db->query("SELECT name,title FROM {$db->pre}fields WHERE tb='$tb' ORDER BY listorder ASC");
$zdtags = array();
while($r = $db->fetch_array($result)){
$zdtags[] = $r;
}
return $zdtags;
}在需要使用的内容页中加上以下代码(我们以供应为例,供应的数据表名是sell_5):
{php $zdtags = xh_fileds_list('sell_5');}
{if $zdtags}
{loop $zdtags $j $a}
{php $name = $a['name'];}
{if $$name}
<tr><th>{$a[title]}</th><td>{$$name}</td></tr>
{/if}
{/loop}
/if}
注意说明:
name显示是双$$
其中 xh_fileds_list('sell_5') 中的sell_5是模块频道的数据表名,商城是 mall_16 ,供应是 sell_5 ,求购是 buy_6 ,查看数据表名请到后台数据库备份那里查看,这里不需要传表前缀。
























18605917465
客服QQ