用途: 类似百度百科,使文章内容信息更丰富;标签内链可以让蜘蛛更好的抓取和收录标签,并有可能抓取该标签下的文章页面,提升整站抓取量。
教程:
主题文件main.PHP添加以下内容:
PHP
if(isset($_POST['tags'])){ $zbp->Config("主题ID")->OpenInLink=GetVars('OpenInLink','POST'); $zbp->SaveConfig('主题ID'); $zbp->ShowHint('good');}
PHP
<?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添加以下内容:
PHP
function ActivePlugin_主题ID(){}下面的这行代码需要加在zblog主题include.php文件里上面{ }内,主题ID修改成当前主题的ID(别名)。Add_Filter_Plugin('Filter_Plugin_ViewPost_Template','主题ID_SetInLinks');
PHP
/*文章标签内链*/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); } }}
小伙伴们觉得麻烦 可以直接用插件:文章标签(Tag)自动内链插件
转载:爱站云
未经允许不得转载! 作者:壹世,转载或复制请以https://www.ym-ym.com/jianzhan/153.html并注明出处壹世品牌网。
原文地址:《Zblog文章tag自动内链,zblog文章内链怎么设置?》发布于:2020-01-11
本文来自网络或网友投稿,如有侵犯您的权益请联系邮箱:xiaochaochaochao@vip.qq.com,我们将第一时间删除。
发表评论