dedecms 获取栏目id(dedecms采集怎么用)

随着互联网技术的飞速发展,内容管理系统(CMS)已经成为许多企业和个人建站的必备工具。DedeCMS作为一款功能强大的开源CMS,深受广大用户的喜爱。在DedeCMS中,获取栏目ID是进行内容管理和定制化开发的基础操作。本文将详细讲解DedeCMS获取栏目ID的实战技巧,并结合案例分析,帮助您轻松掌握这一技能。

一、DedeCMS获取栏目ID的常用方法

1. 直接访问URL获取

在DedeCMS中,每个栏目都有一个对应的URL地址,通过访问该地址,可以直接获取到栏目的ID。以下是一个示例:

栏目名称 栏目URL 栏目ID
新闻中心 /news/ 1
技术文章 /tech/ 2
关于我们 /about/ 3

方法:访问栏目URL,如http://www.example.com/news/,即可获取到新闻中心的栏目ID为1。

2. 通过后台管理获取

DedeCMS后台管理界面提供了查看栏目ID的功能。以下是操作步骤:

(1)登录DedeCMS后台管理界面;

(2)点击“栏目管理”菜单;

(3)在栏目列表中找到目标栏目,查看其ID。

3. 通过数据库查询获取

对于熟悉数据库操作的用户,可以通过查询DedeCMS数据库来获取栏目ID。以下是SQL查询语句:

“`sql

SELECT id FROM dede_arctype WHERE typename = ‘新闻中心’;

“`

说明:根据实际情况修改SQL语句中的表名和字段名。

二、案例分析

1. 案例一:根据栏目ID获取文章列表

假设我们需要根据新闻中心的栏目ID获取最新的文章列表,以下是一个PHP代码示例:

“`php

// 连接数据库

$conn = mysqli_connect(‘localhost’, ‘root’, ‘password’, ‘database’);

// 获取新闻中心栏目ID

$news_id = 1;

// 查询文章列表

$sql = “

dedecms列表页如何调用子栏目列表以及子栏目的名称

dedecms栏目名称的调用方法:{dede:field name=”typename”}调用当前栏目的名称

{dede:channel type='son' row='5'}<a href=”[field:typeurl/]”>[field:typename/]</a>{/dede:channel}调用该顶级频道下所有字栏目,row代表调用5条

{dede:type typeid='栏目id'}<a href=”[field:typeurl/]”>[field:typename/]</a>{/dede:type}表示调用指定id的栏目,只能调用一个。

{dede:channel type='top'}<a>[field:typename/]</a>{/dede:channel}调用子栏目的当前顶级栏目名称。

调用顶级栏目名称示例代码:

{dede:field.titlerunphp=’yes’}list($toptype,$sontype)=split(‘/’,@me);@me=$toptype;{/dede:field.title}

dedecms也叫织梦内容管理系统,是一款知名的PHP开源网站内容管理系统,以简单、实用、开源而闻名,DedeCms免费版的主要目标用户在个人站长,功能更专注于个人网站或中小型门户的构建,当然也不乏有企业用户和学校等在使用。

dedecms模板标签手册:[2]channel|案例详解

标签名称:channel

标记简介:织梦常用标记,通常用于网站顶部以获取站点栏目信息,方便网站会员分类浏览整站信息

功能说明:用于获取栏目列表适用范围:全局使用

typeid参数 typeid='栏目ID'此参数调用指定栏目下的子类{dede:channel typeid='4'} a href='[field:typelink/]'[field:typename/]/a{/dede:channel}

type参数 type='son| sun' son表示下级栏目,self表示同级栏目,top顶级栏目{dede:channel type='top'} a href='[field:typelink/]'[field:typename/]/a{/dede:channel} type参数与模板的环境有关,比如,当浏览“新闻“这个栏目时,那么son就表示“新闻“栏目的子类当栏目下没子类时,type="son"和type="self"调取的数据是一样的,都是当前分类本身。但是在顶级分类中,type="self"获取的将是空数据。首页无法使用type="son"和type="self"

组合查询下面这个模板语句不管在任何页面,调取的都是栏目id为4的同级栏目。{dede:channel typeid='4' type="self" row="1"} a href='[field:typelink/]'[field:typename/]/a{/dede:channel}

其他参数 currentstyle=''应用样式{dede:channel type='son' currentstyle="lia href='~typelink~' class='thisclass'~typename~/a/li"} lia href='[field:typeurl/]'[field:typename/]/a/li{/dede:channel} row='100'调用栏目数

dedecms 列表点击加载更多读取数据库内容怎么实现

使用方法:

1、加载是用AJAX,需要先引用jQuery

2、模板在arcajax.php第二十八行请自行按需修改

3、arcajax.php放到plus目录下

HTML和js代码:

<divid=”loading27″>加载中</div>

<ahref=”javascript:;”id=”getMore”pnum=”2″class=”index-morebgwmt15″>浏览更多案例……</a>

<scripttype=”text/javascript”>

$(“#getMore”).click(function(){

var_this=$(this),

pnum=_this.attr(“pnum”),//分页码

typeid=1;//栏目ID

if(pnum==0){

returnfalse;

}

$(“#loading27”).show();

$.ajax({

url:'/plus/arcajax.php',

data:{typeid:typeid,pnum:pnum},

success:function(data){

if(data!=''){

$(“.index-list”).append(data);//数据显示到页面

_this.attr(“pnum”,Number(pnum)+1);//分页+1

}else{

_this.text(“没有更多的数据”);

_this.attr(“pnum”,0)

}

$(“#loading27”).hide();

}

})

returnfalse;

})

</script>

PHP代码(arcajax.php):

<?php

require_once(dirname(__FILE__).”/../include/common.inc.php”);

require_once(DEDEINC.'/channelunit.class.php');

require_once(DEDEINC.'/taglib/arcpagelist.lib.php');

$pnum=empty($pnum)?0:intval(preg_replace(“/[^\d]/”,'',$pnum));

$typeid=empty($typeid)?0:intval(preg_replace(“/[^\d]/”,'',$typeid));

if($typeid==0||$pnum==0)die(“RequestError!”);

if($typeid>0)

{

$titlelen=AttDef($titlelen,30);

$infolen=AttDef($infolen,160);

$imgwidth=AttDef($imgwidth,120);

$imgheight=AttDef($imgheight,120);

$listtype=AttDef($listtype,'all');

$arcid=AttDef($arcid,0);

$channelid=AttDef($channelid,0);

$orderby=AttDef($orderby,'default');

$orderWay=AttDef($order,'desc');

$subday=AttDef($subday,0);

$line=$row;

$artlist='';

//通过页面及总数解析当前页面数据范围

$strnum=($pnum-1)*12;

$limitsql=”LIMIT$strnum,12″;

$innertext='<li[field:globalname=”autoindex”runphp=”yes”]if(@me%3==0)@me=\'class=”mrnone”\';else@me=””;[/field:global]>

<div><ahref=”[field:arcurl/]”title=”[field:title/]”><imgsrc=”[field:litpic/]”width=”278″height=”245″></a></div>

<h3><ahref=”[field:arcurl/]”title=”[field:title/]”>[field:title/]</a></h3>

<p>[field:descriptionfunction=”cn_substr(@me,150)”/]</p>

<spanclass=”more”><ahref=”[field:arcurl/]”>浏览案例</a></span>

</li>';//模板

//处理列表内容项

$query=”SELECTarc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,

tp.moresite,tp.siteurl,tp.sitepathFROM`#@__archives`arcLEFTJOIN`#@__arctype`tpONarc.typeid=tp.id

WHEREarc.typeidIN(“.GetSonIds($typeid).”)ORDERBYarc.sortrankdesc$limitsql”;

$dsql->SetQuery($query);

$dsql->Execute('al');

$dtp2=newDedeTagParse();

$dtp2->SetNameSpace('field','[',']');

$dtp2->LoadString($innertext);

$GLOBALS['autoindex']=0;

$ids=array();

for($i=0;$i<12;$i++)

{

for($j=0;$j<1;$j++)

{

if($row=$dsql->GetArray(“al”))

{

$ids[]=$row['id'];

//处理一些特殊字段

$row['info']=$row['infos']=cn_substr($row['description'],$infolen);

$row['id']=$row['id'];

if($row['corank']>0&&$row['arcrank']==0)

{

$row['arcrank']=$row['corank'];

}

$row['filename']=$row['arcurl']=GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],

$row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);

$row['typeurl']=GetTypeUrl($row['typeid'],$row['typedir'],$row['isdefault'],$row['defaultname'],$row['ispart'],

$row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);

if($row['litpic']=='-'||$row['litpic']=='')

{

$row['litpic']=$GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';

}

if(!preg_match(“#^http:\/\/#”,$row['litpic'])&&$GLOBALS['cfg_multi_site']=='Y')

{

$row['litpic']=$GLOBALS['cfg_mainsite'].$row['litpic'];

}

$row['picname']=$row['litpic'];

$row['stime']=GetDateMK($row['pubdate']);

$row['typelink']=”<ahref='”.$row['typeurl'].”'>”.$row['typename'].”</a>”;

$row['image']=”<imgsrc='”.$row['picname'].”'border='0'width='$imgwidth'height='$imgheight'alt='”.preg_replace(“#['><]#”,””,$row['title']).”'>”;

$row['imglink']=”<ahref='”.$row['filename'].”'>”.$row['image'].”</a>”;

$row['fulltitle']=$row['title'];

$row['title']=cn_substr($row['title'],$titlelen);

if($row['color']!='')$row['title']=”<fontcolor='”.$row['color'].”'>”.$row['title'].”</font>”;

if(preg_match('#b#',$row['flag']))$row['title']=”<strong>”.$row['title'].”</strong>”;

//$row['title']=”<b>”.$row['title'].”</b>”;

$row['textlink']=”<ahref='”.$row['filename'].”'>”.$row['title'].”</a>”;

$row['plusurl']=$row['phpurl']=$GLOBALS['cfg_phpurl'];

$row['memberurl']=$GLOBALS['cfg_memberurl'];

$row['templeturl']=$GLOBALS['cfg_templeturl'];

if(is_array($dtp2->CTags))

{

foreach($dtp2->CTagsas$k=>$ctag)

{

if($ctag->GetName()=='array')

{

//传递整个数组,在runphp模式中有特殊作用

$dtp2->Assign($k,$row);

}else{

if(isset($row[$ctag->GetName()]))$dtp2->Assign($k,$row[$ctag->GetName()]);

else$dtp2->Assign($k,'');

}

}

$GLOBALS['autoindex']++;

}

$artlist.=$dtp2->GetResult().”

“;

}//ifhasRow

else{

$artlist.='';

}

}//LoopCol

}//loopline

$dsql->FreeResult(“al”);

}else

{

die(“RequestError!”);

}

AjaxHead();

echo$artlist;

exit();

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享