超全常用dedecms织梦SQL标签使用教程汇总

142

注意:wmd_archives这是系统默认的数据库表,如果你修改过表前缀wmd_,请自行更改表名。在以下示例的标签中,有一部分只写出了SQL语句,具体的完整标签写法请参考:织梦SQL标签调用方法
共有文章:** 篇
 
{wmd:sql sql="select count(ID) as c from wmd_archives where channel=1"}·共有文章:[field:c /]篇{/wmd:sql}
共有图集:** 个
 
{wmd:sql sql="select count(ID) as c from wmd_archives where channel=2"}·共有图集:[field:c /]个{/wmd:sql}
共有软件:** 个
{wmd:sql sql="select count(ID) as c from wmd_archives where channel=3"}·共有软件:[field:c /]个{/wmd:sql}
共有评论:**条
{wmd:sql sql="select count(ID) as c from wmd_feedback"}·共有评论:[field:c /]条{/wmd:sql}
共有会员:**名
{wmd:sql sql="select count(ID) as c from wmd_member "}共有会员:[field:c /]名{/wmd:sql}
{wmd:sql sql="select count(mid) as c from wmd_member "}共有会员:[field:c /] 名{/wmd:sql}
文章阅读:** 人次
{wmd:sql sql="select sum(click) as c from wmd_archives"}文章阅读:[field:c /]人次{/wmd:sql}
今日更新:**篇
{wmd:sql sql="SELECT count( ID ) AS c FROM wmd_archives WHERE pubdate > UNIX_TIMESTAMP( CURDATE( ) ) "}今日更新:[field:c /]篇{/wmd:sql}
24小时发布的新文章:
select count(id)+0 as total from wmd_archives where UNIX_TIMES*****P() - pubdate < 86400 and arcrank >=0;
//86400 是 3600 * 24,也就是24小时发布的新文章。
当天发布的最新文章
SELECT count(ID) as count from wmd_archives where pubdate > UNIX_TIMES*****P( FROM_UNIXTIME(UNIX_TIMES*****P(), '%Y-%m-%d 00:00:00'))  limit 1;
当天审核通过的最新文章
SELECT count(ID) as count from wmd_archives where pubdate > UNIX_TIMES*****P( FROM_UNIXTIME(UNIX_TIMES*****P(), '%Y-%m-%d 00:00:00')) and arcrank >0  limit 1;
当天审核通过的最新文章
where to_days(curdate())=to_days(from_unixtime(pubdate)) and arcrank=0
本月更新:**篇
{wmd:sql sql="SELECT count( ID ) AS c FROM cn_archives WHERE FROM_UNIXTIME( pubdate, '%m' ) = month (curdate( )) "} ○ 本月更新:<strong>[field:c /]</strong> 篇;{/wmd:sql}
文章收藏次数:
[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]
统计指定栏目及所有下属分支栏目内的文章数
1、修改include/inc_functions.php文件,增加函数如下:
function GetTotalArc($tid){
$dsql = new DedeSql(false);
$sql = TypeGetSunID($tid,$dsql);
$row = $dsql->GetOne("Select count(ID) as dd From wmd_archives where {$sql}");
return $row['dd'];
}
2、调用方法,在需要修改的模板页插入如下代码(其中的3是栏目ID,根据你的实际情况修改)
{wmd:field function='GetTotalArc(3)'/}
补充一点:如果在栏目模板页面上调用,可以用这个写法,统计当前栏目内的文章数
{wmd:field name='ID'  function='GetTotalArc(@me)'/}
栏目文章统计功能,使用 dedecms 的runphp 接口 编写一个 函数。利用channel标签的ID变量获得函数。
function GetChannelArticleNum($id){
if(!$id || !is_numeric($id)) return 0;
$dsql = new DedeSql();
require_once(dirname(__FILE__)。"/inc_channel_unit_functions.php");
$sql = TypeGetSunID($id,$dsql);
$dsql -> SetQuery("Select count(*) as c From wmd_archives where {$sql}");
$row = $dsql -> GetOne();
return $row['c'];
}
将该函数放入 inc_functions.php 中,示例调用方法:
{wmd:channel type='top' row='8'} | [field:typename/] ([field:ID runphp='yes'] @me = GetChannelArticleNum(@me);[/field:ID]){/wmd:channel}
增加栏目文章统计功能
第一种方法:
修改include/inc_arcpart_view.php文件,找到function ParseTemplet()函数,修改为:
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 wmd_archives where typeid='$tid' and arcrank<>-1");
$this->dtp->Assign($tagid,$row['dd']);
}
调用方法:{wmd:countclass typeid='栏目编号'/}
第二种方法:
修改include/inc_functions.php文件,增加函数如下:
function GetTotalArc($tid){
$dsql = new DedeSql(false);
$row = $dsql->GetOne("Select count(ID) as dd From wmd_archives where typeid='$tid'");
return $row['dd'];
}
调用方法:[field:id function='GetTotalArc(@me)'/]
The End

相关推荐

织梦dedecms生成报错Fatal error: Allowed memory size of in /include
织梦生成静态html页面时报错:Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in /wwwroot/include/helpers/string.helper.php on line 121 字面意思理解是内存不足,很多朋友可能认为是内存不足问题,实际上不...
2023-10-13 dedecms安装使用
329

织梦Dedecms限制栏目列表生成的页数
有时候我们的文档特别的多,另外也是为防止网站被采集,全站文章被索引,所以要控制下织梦dedecms列表页面数量。 这样的话我们要具体怎么操作呢? 1、首先建立一个全局变量: 在系统-站点设置中添加一个新的变量,变量名称:cfg_listmaxpage,变量说明:栏目...
2023-05-24 dedecms安装使用
126

dedecms织梦全局变量调用方法总结
dedecms织梦的全局变量可以在/include/common.inc.php文件中看到,此文件内定义了大量的全局变量,详细自己去看看。 如果我们要实用dedeCMS织梦全局变量该如何调用: 第一种单独调用: {wmd:global.变量名 /},注意闭合,否则会以文本形式输出。这种一般适用...
2023-03-01 dedecms安装使用
238

织梦DEDECMS 栏目文章文章命名规则修改
织梦DEDECMS 栏目文章文章命名规则修改, 每次添加栏目的时候 都要改文章命名规则,十分麻烦, 修改下面这个地方就可以一改永亦,织梦模板网为您解答 找到\include\common.inc.php 搜索 $cfg_df_namerule 把: $cfg_df_namerule = {typedir}/{Y}/{M}{D}/{aid...
2021-09-24 dedecms安装使用
165

解决dedecms织梦系统{wmd:arclist keyword='动态获取关键词'}只生效一次
当我们通过{wmd:arclist keyword=关键词}来调用文章列表时,你会发现只在其中一个栏目里生效,在其他栏目,仍然显示上一次的关键词。 原因是由于arclist的缓存导致的。 只需修改/include/taglib/arclist.lib.php文件,大概在384行: $taghash = md5(seriali...
2021-09-24 dedecms安装使用
212

织梦dedecms数据库内容替换安全确认码怎么去掉
我们在使用织梦dedecms数据库内容替换时候,经常遇到 安全码 显示的无法识别或者不清晰,这个安全码的位置是在核心 - 批量维护 - 数据库内容替换,如果识别不了,这个页面还没有改变验证码的地方,只能重新刷新页面,如果我们不想要这个安全码的话,要怎么操...
2021-09-24 dedecms安装使用
109