destoon 内容页批量调用所有自定义字段的方法

分类栏目:destoon实战

166

destoon 内容页批量调用所有自定义字段的方法

一个一个的在模板里调,是不是太麻烦了,下面的方法就是批量循环出当前频道所有不为空的自定义字段内容。

api/extend.func.php 中添加以下函数


function getfileds($tb){ global $db; $result = $db->query("select name,title from {$db->pre}fields where tb='$tb' order by listorder asc"); $tags = array(); while($r = $db->fetch_array($result)){ $tags[] = $r; } return $tags; }
在内容页中使用 

{php $atts = getfileds('mall');} {loop $atts $i $v} {if $$v[name]}<li>{$v[title]}:{$$v[name]}</li>{/if} {/loop}
注意:其中 getfileds('mall')  中的mall 是当前频道的表名,商城是 mall  供应 sell_5 求购 buy_6  更我表名请到后台数据库备份那里查看,这里不需要传表前缀。