首页 未命名内容详情

Zblog文章tags自动内链代码

2026-01-10 3 897698882
Zblog文章tags自动内链代码

站点名称:Zblog文章tags自动内链代码

所属分类:未命名

官方网址:

SEO查询: 爱站网 站长工具

进入网站

站点介绍

用途:  类似百度百科,使文章内容信息更丰富;标签内链可以让蜘蛛更好的抓取和收录标签,并有可能抓取该标签下的文章页面,提升整站抓取量。

教程:

主题文件main.php添加以下内容:

if(isset($_POST['tags'])){  $zbp->Config("主题ID")->OpenInLink=GetVars('OpenInLink','POST');  $zbp->SaveConfig('主题ID');  $zbp->ShowHint('good');
<?php  }  if ($act == 'tags'){?><form id="form1" name="form1" method="post"><table width="100%" style='padding:0;margin:0;' cellspacing='0' cellpadding='0' class="tableBorder">    <tr>        <th width="15%"><p align="center">配置名称</p></th>        <th width="50%"><p align="center">配置内容</p></th>        <th width="25%"><p align="center">配置说明</p></th>    </tr>    <tr>        <td width="450px"><p align="center">开启标签内链</p></td>        <td><p align="center"><label onclick="$('#ZC_BLOG_HOST').prop('readonly', $('#ZC_PERMANENT_DOMAIN_ENABLE').val()==0?true:false);"><input type="text" id="ZC_PERMANENT_DOMAIN_ENABLE" name="OpenInLink" class="checkbox" value="<?php echo $zbp->Config('主题ID')->OpenInLink?$zbp->Config('主题ID')->OpenInLink:"0";?>"/></label></p></td>							<?php if (function_exists('CheckIsRefererValid')) {echo '<input type="hidden" name="csrfToken" value="' . $zbp->GetCSRFToken() . '">';}?>		<td><p align="left">本主题支持文章自动标签内链,如果你安装了类似“标签自动内链”插件后产生冲突,请关闭此开关即可!</p></td>    </tr>    <tr>        <td colspan="4"><input name="" type="Submit" class="button" value="保存"/></td>    </tr></table>

主题文件include.php添加以下内容:

function ActivePlugin_主题ID(){}下面的这行代码需要加在zblog主题include.php文件里上面{ }内,主题ID修改成当前主题的ID(别名)。Add_Filter_Plugin('Filter_Plugin_ViewPost_Template','主题ID_SetInLinks');
/*文章标签内链*/function 主题ID_SetInLinks(&$t){    global $zbp;    if($zbp->Config('主题ID')->OpenInLink==1)    {        $article=$t->GetTags('article');        if(count($article)>0)        {            $content=$article->Content;            $allTags=$zbp->GetTagList(null, null, array('LENGTH(tag_Name)' => 'DESC'), null, null);            foreach ($allTags as $inlink)            {                $error_name=array('(',')','|','[','<','^','\\');                $error_t=false;                foreach ($error_name as $e)                {                    if(strpos($inlink->Name,$e))                    {                        $error_t=true;                        break;                    }                }                if ($error_t==true)                {                    continue;                }                $content=preg_replace('/(?!((<.*?)|(<a.*?)))('.$inlink->Name.')(?!(([^<>]*?)>)|([^>]*?<\/a>))/i','<a target="_blank" href="'.$inlink->Url.'" style="text-decoration: none;">'.$inlink->Name.'</a>',$content,1);//color:'.$zbp->Config('主题ID')->TagsStyle.'            }            $article->Content=$content;            $t->SetTags('article',$article);        }    }}