dedecms万能SQL标签使用方法大全

2019-04-2512:01:59网站建设与开发Comments2,406 views字数 3170阅读模式

dede_archives这是系统默认的数据库表,如果你修改过表前缀dede_,请自行更改表名。在以下示例的标签中,有一部分只写出了SQL语句,具体的完整标签写法请参考:织梦SQL标签调用方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

共有文章:** 篇文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

{dede:sql sql="select count(ID) as c from dede_archives where channel=1"}·共有文章:[field:c /]篇{/dede:sql}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

共有图集:** 个文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

{dede:sql sql="select count(ID) as c from dede_archives where channel=2"}·共有图集:[field:c /]个{/dede:sql}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

共有软件:** 个文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

{dede:sql sql="select count(ID) as c from dede_archives where channel=3"}·共有软件:[field:c /]个{/dede:sql}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

共有评论:**条文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

{dede:sql sql="select count(ID) as c from dede_feedback"}·共有评论:[field:c /]条{/dede:sql}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

共有会员:**名文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

{dede:sql sql="select count(ID) as c from dede_member "}共有会员:[field:c /]名{/dede:sql}
{dede:sql sql="select count(mid) as c from dede_member "}共有会员:[field:c /] 名{/dede:sql}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

文章阅读:** 人次文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

{dede:sql sql="select sum(click) as c from dede_archives"}文章阅读:[field:c /]人次{/dede:sql}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

今日更新:**篇文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

{dede:sql sql="SELECT count( ID ) AS c FROM dede_archives WHERE pubdate > UNIX_TIMESTAMP( CURDATE( ) ) "}今日更新:[field:c /]篇{/dede:sql}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

24小时发布的新文章:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

select count(id)+0 as total from dede_archives where UNIX_TIMES*****P() - pubdate < 86400 and arcrank >=0;
//86400 是 3600 * 24,也就是24小时发布的新文章。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

当天发布的最新文章文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

SELECT count(ID) as count from dede_archives where pubdate > UNIX_TIMES*****P( FROM_UNIXTIME(UNIX_TIMES*****P(), '%Y-%m-%d 00:00:00')) limit 1;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

当天审核通过的最新文章文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

SELECT count(ID) as count from dede_archives where pubdate > UNIX_TIMES*****P( FROM_UNIXTIME(UNIX_TIMES*****P(), '%Y-%m-%d 00:00:00')) and arcrank >0 limit 1;文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

当天审核通过的最新文章文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

where to_days(curdate())=to_days(from_unixtime(pubdate)) and arcrank=0文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

本月更新:**篇文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

{dede:sql sql="SELECT count( ID ) AS c FROM cn_archives WHERE FROM_UNIXTIME( pubdate, '%m' ) = month (curdate( )) "} ○ 本月更新:<strong>[field:c /]</strong> 篇;{/dede:sql}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

文章收藏次数:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

[field:ID runphp='yes']$dsql = new dedesql();$dsql -> SetQuery("select count(*) as c from cn_member_stow where aid=".@me);$nic_row = $dsql -> getone();@me=$nic_row['c'];[/field:ID]文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

统计指定栏目及所有下属分支栏目内的文章数文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

1、修改include/文件,增加函数如下:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

function GetTotalArc($tid){
$dsql = new DedeSql(false);
$sql = TypeGetSunID($tid,$dsql);
$row = $dsql->GetOne("Select count(ID) as dd From dede_archives where {$sql}");
return $row['dd'];
}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

2、调用方法,在需要修改的模板页插入如下代码(其中的3是栏目ID,根据你的实际情况修改)文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

{dede:field function='GetTotalArc(3)'/}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

补充一点:如果在栏目模板页面上调用,可以用这个写法,统计当前栏目内的文章数文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

{dede:field name='ID' function='GetTotalArc(@me)'/}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

栏目文章统计功能,使用 dedecms 的runphp 接口 编写一个 函数。利用channel标签的ID变量获得函数。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

function GetChannelArticleNum($id){
if(!$id || !is_numeric($id)) return 0;
$dsql = new DedeSql();
require_once(dirname(__FILE__)。"/");
$sql = TypeGetSunID($id,$dsql);
$dsql -> SetQuery("Select count(*) as c From dede_archives where {$sql}");
$row = $dsql -> GetOne();
return $row['c'];
}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

将该函数放入 中,示例调用方法:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

{dede:channel type='top' row='8'} | [field:typename/] ([field:ID runphp='yes'] @me = GetChannelArticleNum(@me);[/field:ID]){/dede:channel}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

增加栏目文章统计功能文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

第一种方法:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

修改include/文件,找到function ParseTemplet()函数,修改为:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

function ParseTemplet()
{
if(!is_array($this->dtp->CTags)) return "";
foreach($this->dtp->CTags as $tagid=>$ctag)
{
$tagname = $ctag->GetName();
//countclass 统计栏目文章数量
if( $tagname == "countclass" ){
$tid = $ctag->GetAtt("typeid");
$row = $this->dsql->GetOne("Select count(ID) as dd From dede_archives where typeid='$tid' and arcrank<>-1");
$this->dtp->Assign($tagid,$row['dd']);
}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

调用方法:{dede:countclass typeid='栏目编号'/}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

第二种方法:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

修改include/文件,增加函数如下:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

function GetTotalArc($tid){
$dsql = new DedeSql(false);
$row = $dsql->GetOne("Select count(ID) as dd From dede_archives where typeid='$tid'");
return $row['dd'];
}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

调用方法:[field:id function='GetTotalArc(@me)'/]文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/11582.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/cms/11582.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定