织梦二次开发教程之设置内容文章标题是否显示网站名称

简介:今天,小千个人博客,写篇关于网站标题SEO优化的教程,织梦二次开发之设置文章内容标题是否显示网站名称。很多时候,我们不想显示标题的时候,可以设置不显示标题,有利于网站SEO优化。

任何网站,网站的文章标题,都是默认带后缀,小尾巴的,这点,谁都不敢否认,如果,你想某篇文章,不想显示网站名称,不想显示文章小尾巴,这个可以说是很难做到。其实,像这种需求,是可以实现的,只不过是需要改一下就能实现了,下面,小千个人博客网站,就给大家出这么一篇反面教程,说它是反面教材,因为它真的能让你的网站实现权重暴涨。

好了,废话就不多说了,具体的效果呢?下面小千用代码的形式展示一下,如果,你觉得是你想要的效果,那你就可以改吧,如果不是你想要的那种效果,你就不用改了。

展示效果图

织梦二次开发教程之设置内容文章标题是否显示网站名称-小千织梦模板

展示效果

没改之前显示的网站标题
<title>{dede:field.title/} - {dede:global.cfg_webname/}</title>
显示效果:文章标题名称 - 网站名称


改了之后显示的网站标题
<title>{dede:field.id function='GetaTitle(@me)'/}</title>
开启标题显示效果:文章标题名称 - 网站名称
关闭标题显示效果:文章标题名称

对的,没错,这就是鲜明的对比,标题调用标签改了,然后标题后缀,就是网站名称小尾巴,可以关闭,也可以显示。当你有某篇文章,不想显示网站标题的时候,这个时候就可以关闭显示网站标题。大概就是这样的效果啦,下面开始教大家做修改教程,小千纯原创,网上没有的,因为这是一小伙伴的需求,我觉得挺有意思的,就写出来分享一下给大家使用。

开始教程

①、打开 /dede/article_add.htm 搜索

文章标题

将它的 tr 这整块代码改为

<tr>
        <td height="26" colspan="5" class="bline">
          <table width="900" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="90" style="padding-left:10px">文章标题:</td>
              <td width="515"><input name="title" type="text" id="title" value="<?php echo $title; ?>" style="width:380px">
<style type="text/css">
.search_fo,.search_fo_click{cursor:pointer;width:130px;height:29px;line-height:29px;background:#28a745;color:#FFFFFF;float:right;text-align:center}
.search_fo:hover,.search_fo_click:hover{background:#dc3545;color:#FFFFFF}
</style>
<?php
if ($_COOKIE["search_fo"]=='1' || $mingcheng=='1'){
	$fo_class='search_fo_click';
	$fo_str='显示网站名称';
	$mingcheng='1';
}else{
	$_COOKIE["search_fo"]='0';
	$fo_class='search_fo';
	$fo_str='不显示网站名称';
	$mingcheng='0';
}
?>
<div id="search_fo" class="<?php echo $fo_class?>"><?php echo $fo_str;?></div>
<input type="hidden" name="mingcheng" id="mingcheng" value="<?php echo $mingcheng;?>">
<script type="text/javascript" src="js/jquery.cookie.js"></script>
			  </td>
              <td width="90" style="padding-left:10px">简略标题:</td>
              <td><input name="shorttitle" type="text" id="shorttitle" style="width:150px"></td>
            </tr>
          </table>
        </td>
</tr>

②、打开 /dede/article_edit.htm 搜索

文章标题

将它的 tr 这整块代码改为

<tr>
        <td height="26" colspan="2" class="bline">
          <table width="900" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="90" style="padding-left:10px">文章标题:</td>
              <td width="515"><input name="title" type="text" id="title" value="<?php echo $arcRow['title']; ?>" style="width:380px">
<style type="text/css">
.search_fo,.search_fo_click{cursor:pointer;width:130px;height:29px;line-height:29px;background:#28a745;color:#FFFFFF;float:right;text-align:center}
.search_fo:hover,.search_fo_click:hover{background:#dc3545;color:#FFFFFF}
</style>
<?php
if ($arcRow['mingcheng']=='1'){
	$fo_class='search_fo_click';
	$fo_str='显示网站名称';
	$arcRow['mingcheng']='1';
}else{
	$fo_class='search_fo';
	$fo_str='不显示网站名称';
	$arcRow['mingcheng']='0';
}
?>
<div id="search_fo" class="<?php echo $fo_class?>"><?php echo $fo_str;?></div>
<input type="hidden" name="mingcheng" id="mingcheng" value="<?php echo $arcRow['mingcheng']; ?>">
<script type="text/javascript" src="js/jquery.cookie.js"></script>
			  </td>
              <td width="90" style="padding-left:10px">简略标题:</td>
              <td><input name="shorttitle" type="text" id="shorttitle" style="width:150px" value="<?php echo $arcRow['shorttitle']; ?>"></td>
            </tr>
          </table>
        </td>
</tr>

③、打开 /dede/article_add.php 搜索

//保存到主表

看到这句,在它后面加一个字段 mingcheng

//保存到主表
$query = "INSERT INTO `#@__archives`(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,color,writer,source,litpic,pubdate,senddate,mid,voteid,notpost,description,keywords,filename,dutyadmin,weight,mingcheng)
VALUES ('$arcID','$typeid','$typeid2','$sortrank','$flag','$ismake','$channelid','$arcrank','$click','$money','$title','$shorttitle','$color','$writer','$source','$litpic','$pubdate','$senddate','$adminid','0','$notpost','$description','$keywords','$filename','$adminid','$weight','$mingcheng');";

注意:里面有两个地方需要加 mingcheng 字段的。

④、打开 /dede/article_edit.php 搜索

weight='$weight'

改为

weight='$weight',mingcheng='$mingcheng'

后台的四个文件就改完了。

下载JS文件

本地下载

下载以后就解压到你的后台目录下的js目录中。

文件路径是 /dede/js/jquery.cookie.js

织梦二次开发教程之设置内容文章标题是否显示网站名称-小千织梦模板

剪切到里面去就行了。

添加方法

打开 /include/extend.func.php 在它下面添加一个方法,代码如下;

/**
 *  是否显示内容文章网站标题
 */
if(!function_exists('GetaTitle'))
{
	function GetaTitle($id)
	{
		global $cfg_webname,$dsql;
		$row = $dsql->GetOne("SELECT mingcheng,title FROM `#@__archives` WHERE id=".$id."");
		if($row['mingcheng'] == '' || $row['mingcheng'] == '1')
		{
			$micheng = ''.$row['title'].' - '.$cfg_webname.'';
		}else{
			$micheng = $row['title'];
		}
		return $micheng;
	}
}

添加字段

添加字段 (后台-系统-SQL命令行工具-执行)

ALTER TABLE `#@__archives` ADD `mingcheng` CHAR(15) NOT NULL DEFAULT '1';

调用标签

article_article.htm模板,文章标题调用标签

<title>{dede:field.title/}_{dede:global.cfg_webname/}</title>

改为

<title>{dede:field.id function='GetaTitle(@me)'/}</title>

不需要调用标题和网站名称了。操作完成了,是不是超级简单啊,哈哈。如果调用不对,那就仔细观看修改步骤,记得,按步骤认真操作,你肯定会成功的。

这篇文章由《织梦爱好者》发布在《小千织梦模板》网的,主要是为大家详细介绍了织梦二次开发教程之设置内容文章标题是否显示网站名称,感谢织梦爱好者分享这篇具有一定参考价值的织梦教程,感兴趣的小伙伴们可以参考一下教程,有需要的朋友可以收藏方便以后借鉴。

以上便是小千给大家分享的织梦二次开发教程之设置内容文章标题是否显示网站名称,希望对大家有所帮助,如果想了解更多织梦教程、织梦二次开发教程,请关注小千资源网吧~

版权声明:本文为博主原创文章,未经博主允许不得转载。http://nikucms.com/w/980.html

织梦教程2023-04-06

织梦爱好者

织梦爱好者织梦爱好者注册会员

没有挖不倒的墙角,只有不努力的小三!

优惠券