织梦CMS|网站导航当前栏目高亮显示、特定导航链接nofollow

in cn •  6 years ago 

今天花了半天的时间攻克了两个织梦难题,分别是:网站导航当前栏目高亮显示,和特定栏目链接添加nofollow标签。

当前栏目高亮

1546784912074.png

如上图,修改前,“网站首页”的导航文本不会高亮显示。(红色虚线框是nofollow检查插件,用户不会看到。)

我们知道织梦的导航栏调用代码不能调用出首页,只能调用一级及以下栏目,所以导航代码一般为以下形式:

<li>富凯首页</li>

{dede:channel
<li>栏目标题</li>
{/dede:channel}

我使用改造前我使用的代码如下:

<ul>
<li><a href="{dede:global.cfg_basehost/}"><span class="name">富凯首页</span></a></li>

 {dede:channel type='top' row='8' currentstyle="<li class='current'><a href='~typelink~' class='name'>~typename~</a> </li>"}
<li>
<a href='[field:typelink/]'>[field:typename/]</a>
</li>
{/dede:channel}
</ul>

以前在网上找过首页设置高亮的方法,但是没有完成。再次尝试,应该是自己搜索能力变强了,这次终于找到了解决办法:

参考文章

如果一个内容被判断当前栏目后,让左侧导航高亮显示.可以这样写,意思是,如果本文章所在栏目属于上级目录1,或子目录2或8,本代码都将高亮显示.

<li  {dede:field name=typeid runphp='yes'}(@me=='1'||@me=='2'||@me=='8')?@me=' class="active3"':@me='';{/dede:field}>{dede:type typeid=2}<a  href="[field:typeurl /]"> [field:typename /]{/dede:type}<span class="arrow"></a></li>

于是修改调用首页栏目链接代码为:

<li {dede:field name=typeid runphp="yes"}(@me=="")? @me=" class='current' ":@me="";{/dede:field}><a href="{dede:global.cfg_basehost/}"><span class="name">富凯首页</span></a></li>

首页高亮修改完成。

特定导航链接添加nofollow标签

大家都知道,导航中的联系我们页面中没有实际内容,从SEO方面考虑页面重要程度不高。但对用户转化率非常重要。所以我们可以把导航栏中的“联系我们”的链接加上nofollow标签,避免它分散其他页面的权重。

所以我们要把它单独处理,设置nofollow标签:

<li>富凯首页</li>

{dede:channel
<li>栏目标题</li>
{/dede:channel}

<li>联系我们</li>

实际代码如下:

<ul>

<li {dede:field name=typeid runphp="yes"}(@me=="")? @me=" class='current' ":@me="";{/dede:field}><a href="{dede:global.cfg_basehost/}"><span class="name">富凯首页</span></a></li>

{dede:channel type='top' row='3' currentstyle="<li class='current'><a href='~typelink~' class='name'>~typename~</a> </li>"}
<li>
<a href='[field:typelink/]'>[field:typename/]
</a>
</li>
{/dede:channel}

<--!下面代码的意思是:如果这个页面调用的是ID为3栏目的内容,那么-->
<li {dede:field name=typeid runphp="yes"}(@me=="3")? @me=" class='current' ":@me="";{/dede:field}>
{dede:type typeid=3}<a rel="nofollow"  href="[field:typeurl /]"> {/dede:type}<span class="name">联系我们</span></a>
</li>

</ul>

<a>标签中加入rel="nofollow”即可。

需要注意的是,因为“联系我们”的被独立处理了,为了高亮显示,需要加如参考文章中的确定当前页面代码,其中,(@me=="3")和typeid=3与参考文章相比都加了一个3,是因为我的“联系我们”栏目的ID为3。你在修改时需要换成你的网站栏目对应的ID。


参考文章

织梦dedecms获取当前内容页栏目id号的方法

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @lixing! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You published a post every day of the week

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Support SteemitBoard's project! Vote for its witness and get one more award!

thx 4 the upvote!

AlphaOmegaEnergy (aoecoin) the World's #1 Breakthrough CleanEnergy Startup is going on the Blockchain this year with 2,922 new techs.

  • We are doing a Seedround on Blockchain
  • Paying 300% Fixed Return Minimum to our Investors as a debt note.
  • Pre-sales are open now DM to invest.
  • We will be building power plants with our world leading technology, as an asset backed Blockchain. We are mining with the power we make, and building an electric plane and several scalable social enterprise divisions as well.
  • We are securing the Seedround chain also with 100% collateral in shares of the company and a debt note. We have every receipt practically in triplicate.
  • Make a Big Return helping us CHARGE IT ALL! And Change The World!!
  • We will Comment your post, follow, and or up vote every time you support one of our posts or make positive comments! All promoters send me your win-win services & solutions!

Can visit our steemit and check us out!
https://steemit.com/@aoecoin

We changed The World.png

Congratulations @lixing! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!