dedecms获取当前url(html获取当前页面地址)

在DedeCMS中,获取当前URL是一个常见的需求,无论是为了SEO优化,还是为了实现一些功能,比如判断用户是否处于登录状态,或者是判断用户是否访问的是特定页面等。下面,我就来和大家分享一下我在DedeCMS中获取当前URL的一些技巧和心得。

一、DedeCMS获取当前URL的方法

在DedeCMS中,获取当前URL主要有以下几种方法:

1. 使用$_SERVER全局变量

$_SERVER 是一个包含头信息、路径和脚本位置等信息的关联数组。其中,$_SERVER[‘REQUEST_URI’] 可以获取当前请求的URL。

“`php

$url = $_SERVER[‘REQUEST_URI’];

echo $url;

>

“`

2. 使用DedeCMS内置函数

DedeCMS提供了一些内置函数,可以方便地获取当前URL。

  • GetCurUrl():获取当前请求的URL。
  • GetCurUrlParam():获取当前URL的指定参数值。

“`php

$url = GetCurUrl();

echo $url;

>

“`

3. 使用PHP内置函数

PHP内置函数parse_url()可以将URL解析成不同的组成部分。

“`php

$url = ‘http://www.example.com/index.php?name=value’;

$parts = parse_url($url);

echo $parts[‘path’]; // 输出:/index.php

>

“`

二、获取当前URL的注意事项

在使用上述方法获取当前URL时,需要注意以下几点:

1. URL编码:当URL中包含特殊字符时,需要对其进行URL编码,否则可能会导致解析错误。

2. URL参数:当URL中包含多个参数时,需要明确需要获取的参数。

3. URL路径:当需要获取URL的路径部分时,可以使用parse_url()函数的path参数。

三、实战案例

下面,我将通过一个实战案例,为大家展示如何在DedeCMS中获取当前URL。

案例:判断用户是否访问的是首页。

“`php

$url = GetCurUrl();

if ($url == ‘/index.php’) {

echo ‘当前访问的是首页’;

} else {

echo ‘当前访问的不是首页’;

}

>

“`

解析:这段代码首先使用GetCurUrl()函数获取当前URL,然后通过比较获取到的URL是否为首页的URL(即/index.php)来判断用户是否访问的是首页。

四、总结

以上就是我在DedeCMS中获取当前URL的一些技巧和心得。在实际开发过程中,我们可以根据需求选择合适的方法来获取当前URL。希望这篇文章能对大家有所帮助。

方法 优点 缺点
使用$_SERVER全局变量 代码简单,易于理解 需要手动处理URL编码
使用DedeCMS内置函数 代码简洁,易于使用 需要了解DedeCMS的内置函数
使用PHP内置函数 功能强大,可扩展性强 代码相对复杂

获取当前URL是DedeCMS开发中的一项基本技能,希望大家通过本文的学习,能够熟练掌握这一技能。

织梦Dedecms系统SEO优化之网站URL目录优化

1:织梦CMS国内第一大开源程序,系统成熟,利于开发上手。WEB应用中织梦占比30%,WP占比20%,DZ占比13%,帝国CMS占比5.7%。

2:占用服务器资源少,性能优越。

3:前端模板做到精简,利于搜索爬虫抓取。

4:URL可静态化,目录及文件名可通过后台设置。

5:缺点是手机站是M目录形式,需二次改进或做独立系统手机站。适配教麻烦,尽可能选择响应式模板,用自适应方式完成移动适配。

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();

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免费版的主要目标用户在个人站长,功能更专注于个人网站或中小型门户的构建,当然也不乏有企业用户和学校等在使用。

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