当我们用dedecms建站时,为了seo优化,有时想禁止某个栏目被爬虫爬取,这就需要给此栏目添加rel="nofollow"属性标签。在此通过网站资料的整理和自己的摸索,给大家分享一下【亲测可行】的给织梦导航栏自定义自动添加nofollow的实现方法。
实现的功能
1、在创建栏目时可以,自定义是否添加nofollow属性;
2、在修改栏目时也可以修改是否添加nofollow属性;
3、在调用导航栏时,可以自定义自动添加nofollow属性,实现方法简单、灵活。
修改后,导航栏调用nofollow属性实现代码
{dede:channel type='top' row='8'} <a href='[field:typelink/]' [field:nofollow/]>[field:typename/]</a> {/dede:channel}
如何实现给导航栏(下拉菜单)添加nofollow功能的操作步骤
第一步、在dede数据库中,修改dede_arctype表结构,添加nofollow字段,如图。
第二步、设置nofollow字段属性,见下图,点击保存。
第三步、修改织梦后台模板文件dede\templets 模版:catalog_add.htm、catalog_edit.htm
在catalog_add.html文件中,搜索“多站点支持”,在其上面添加如下代码:
<tr> <td class='bline' width="150" height="24" style="padding-left:10px;">nofollow:</td> <td class='bline'> <input name="nofollow" type="radio" class="np" value="" checked="checked"/> 不添加 <input type="radio" name="nofollow" class="np" value="rel='nofollow'"/> 添加 </td> </tr>
同样,在catalog_edit.htm文件中,搜索“多站点支持”,在其上添加如下代码:
<tr> <td class='bline' width="150" height="24" style="padding-left:10px;">nofollow:</td> <td class='bline'> <input name="nofollow" type="radio" class="np" value=""<?php if($myrow['nofollow']=='') echo " checked='1' ";?>/> 不添加 <input type="radio" name="nofollow" class="np" value="rel='nofollow'"<?php if($myrow['nofollow']=="rel='nofollow'") echo " checked='1' ";?>/> 添加 </td> </tr>
第四步、修改织梦后台模板文件dede目录下的:catalog_add.php、catalog_edit.php文件。
修改catalog_add.php文件,搜索“queryTemplate”,将此句修改为如下代码,改动后见下图效果:
$queryTemplate = "INSERT INTO `#@__arctype`(reid,topid,sortrank,typename,typedir,isdefault,defaultname,issend,channeltype, tempindex,templist,temparticle,modname,namerule,namerule2,ispart,corank,description,keywords,seotitle,moresite,siteurl,sitepath,ishidden,`cross`,`crossid`,`content`,`smalltypes`,`nofollow`) VALUES('~reid~','~topid~','~rank~','~typename~','~typedir~','$isdefault','$defaultname','$issend','$channeltype', '$tempindex','$templist','$temparticle','default','$namerule','$namerule2','0','0','','','~typename~','0','','','0','0','0','','','$nofollow')";
修改catalog_add.php文件,搜索“$in_query”,将此句修改为如下代码,改动后见下图效果:
$in_query = "INSERT INTO `#@__arctype`(reid,topid,sortrank,typename,typedir,isdefault,defaultname,issend,channeltype, tempindex,templist,temparticle,modname,namerule,namerule2, ispart,corank,description,keywords,seotitle,moresite,siteurl,sitepath,ishidden,`cross`,`crossid`,`content`,`smalltypes`,`nofollow`) VALUES('$reid','$topid','$sortrank','$typename','$typedir','$isdefault','$defaultname','$issend','$channeltype', '$tempindex','$templist','$temparticle','default','$namerule','$namerule2', '$ispart','$corank','$description','$keywords','$seotitle','$moresite','$siteurl','$sitepath','$ishidden','$cross','$crossid','$content','$smalltypes','$nofollow')";
修改catalog_edit.php文件,搜索“upquery”,将此句修改为如下代码,改动后见下图效果:
$upquery = "UPDATE `#@__arctype` SET issend='$issend', sortrank='$sortrank', typename='$typename', typedir='$typedir', isdefault='$isdefault', defaultname='$defaultname', issend='$issend', ishidden='$ishidden', channeltype='$channeltype', tempindex='$tempindex', templist='$templist', temparticle='$temparticle', namerule='$namerule', namerule2='$namerule2', ispart='$ispart', corank='$corank', description='$description', keywords='$keywords', seotitle='$seotitle', moresite='$moresite', `cross`='$cross', `content`='$content', `crossid`='$crossid', `smalltypes`='$smalltypes', `nofollow`='$nofollow' $uptopsql WHERE id='$id' ";
第五步、此步是重点,网上的教程,都有写上面的过程,但是这个修改很少有写,所以导致网上的大部分方法无效。
修改include/taglib/channel.lib.php文件,搜索“$type=='top'”,修改sql语句,修改后代码如下:
$sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,nofollow From `#@__arctype` WHERE reid=0 And ishidden<>1 order by sortrank asc limit 0, $line ";
下面的$type='son'、$type='self',对应的sql语句也在同样的位置加上nofollow,即可。
最后,通过修改织梦系统文件,实现了给导航栏自定义自动添加nofollow属性标签的功能,该实现方法简单、灵活、简介,推荐大家使用。如有不懂,联系我哦。
更多相关推荐
版权保护:本文《怎么给dede织梦导航栏调用增加nofollow》由<我爱分享>原创,转载请保留链接:http://www.shuidi365.cn/site/130.html
此博客主要用来分享、推荐自己日常、学习过程中感觉比较实用的经验、IT技术和一些比较好的资源(各种软件、各种开发手册、各种学习资料、各种视频教程等),希望对大家有所帮助,有问题请留言,欢迎来交流,联系QQ邮箱/微信:342807450