乖兔博客

乖兔 > CMS系统 > 织梦DEDECMS列表页和文章页调用评论数和收藏数

织梦DEDECMS列表页和文章页调用评论数和收藏数

乖兔 更新于: 2020-03-06 分类:CMS系统

织梦DEDECMS调用评论数和收藏数量代码写法.jpg

织梦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>


打赏