Zblog文章tags自動內鏈代碼
用途: 類似百度百科,使文章內容信息更豐富;標簽內鏈可以讓蜘蛛更好的抓取和收錄標簽,并有可能抓取該標簽下的文章頁面,提升整站抓取量。
教程:
主題文件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); } }}
版權聲明:本文來自網絡,不代表老魚網立場,老魚網僅為分享信息,不參與任何交易,也非中介,所有內容僅代表個人觀點,均不作直接、間接、法定、約定的保證,讀者相關風險自擔。
如有侵權,請聯系:wwwlaoyuwang#126.com(#=@)!我們會第一時間核實處理!
如有侵權,請聯系:wwwlaoyuwang#126.com(#=@)!我們會第一時間核實處理!