织梦cms在不同页面调用评论数和收藏数的写法是不同的,并且此处给出的是使用mysql语句来将评论数和收藏数生成静态htm的方式来调用的,非js或者php的动态输出方式。(动态调用方法已经更新,请参见文章尾部方法)
{dede:field.id runphp='yes'}global $dsql;$dsql -> SetQuery("Select count(id) as c from dede_feedback where aid=".@me);$row = $dsql -> getone();@me=$row['c'];{/dede:field.id}
{dede:field.id runphp='yes'}$dsql = new dedesql();$dsql -> SetQuery("select count(*) as c from dede_member_stow where aid=".@me);$row = $dsql -> getone();@me=$row['c'];{/dede:field.id}
[field:ID runphp='yes']global $dsql;$dsql -> SetQuery("Select count(id) as c from dede_feedback where aid=".@me);$row = $dsql -> getone();@me=$row['c'];[/field:ID]
[field:ID runphp='yes']$dsql = new dedesql();$dsql -> SetQuery("select count(*) as c from dede_member_stow where aid=".@me);$row = $dsql -> getone();@me=$row['c'];[/field:ID]
①在plus目录建立一个php并取名为count.php,里面添加代码如下:
document.write("<?php require_once(dirname(__FILE__)."/../include/common.inc.php"); $row = $db->GetOne("select count(*) as fc from dede_feedback where aid='{$aid}'"); if(!is_array($row)){ echo "0"; }else { echo $row['fc']; }?>");
②在要显示评论数量的模板位置使用下面代码进行调用:
<script type="text/javascript" src="{dede:field name='phpurl'/}/count.php?aid={dede:field.id/}"></script>