ZBLOG实现指定分类下文章蜘蛛抓取正常用户404
ZBLOG实现指定分类下文章蜘蛛抓取正常用户404,就是指定某个栏目下的文章,搜索蜘蛛抓取时是正常的,但普通用户浏览是404。可以通过判断代码来实现。
ZBLOG文章页模板路径:(修改后,在后台--主题管理重启一下模板,或者在主机里修改一下模板文件夹名,再改回来)
/zb_users/theme/模板名/template/single.php
代码如下:
<?php die();?>
{if $article.Category.ID =='8'}
{php}
$useragent = addslashes(strtolower($_SERVER['HTTP_USER_AGENT']));
$bot='';
if (strpos($useragent, 'googlebot')!== false){$bot = 'Google';}
elseif (strpos($useragent,'mediapartners-google') !== false){$bot = 'Google Adsense';}
elseif (strpos($useragent,'baiduspider') !== false){$bot = 'Baidu';}
elseif (strpos($useragent,'sogou spider') !== false){$bot = 'Sogou';}
elseif (strpos($useragent,'sogou web') !== false){$bot = 'Sogou web';}
elseif (strpos($useragent,'48.0.2564.116') !== false){$bot = 'baidu';}
elseif (strpos($useragent,'sosospider') !== false){$bot = 'SOSO';}
elseif (strpos($useragent,'360spider') !== false){$bot = '360Spider';}
elseif (strpos($useragent,'yahoo') !== false){$bot = 'Yahoo';}
elseif (strpos($useragent,'msn') !== false){$bot = 'MSN';}
elseif (strpos($useragent,'msnbot') !== false){$bot = 'msnbot';}
elseif (strpos($useragent,'sohu') !== false){$bot = 'Sohu';}
elseif (strpos($useragent,'yodaoBot') !== false){$bot = 'Yodao';}
elseif (strpos($useragent,'twiceler') !== false){$bot = 'Twiceler';}
elseif (strpos($useragent,'ia_archiver') !== false){$bot = 'Alexa_';}
elseif (strpos($useragent,'iaarchiver') !== false){$bot = 'Alexa';}
elseif (strpos($useragent,'slurp') !== false){$bot = '雅虎';}
elseif (strpos($useragent,'bot') !== false){$bot = '其它蜘蛛';}
{/php}
{if $bot !=''}
{template:header}
{if $article.Type==ZC_POST_TYPE_ARTICLE}
{template:post-single}
{else}
{template:post-page}
{/if}
{template:footer}
{else}
<p style="padding:50px;text-align:center;">404 NO FOUND!</p>
{/if}
{else}
{template:header}
{if $article.Type==ZC_POST_TYPE_ARTICLE}
{template:post-single}
{else}
{template:post-page}
{/if}
{template:footer}
{/if}
如果需要某个分类下的文章源代码存在,但TITLE为404,可以使用以下的代码:
{if $article.Category.ID =='8'}
<script>
$('title').html('404 Not Found');
$('body').html('<!DOCTYPE html>\n' +
'<html lang="en">\n' +
'<head>\n' +
' <meta charset="UTF-8">\n' +
' <meta name="viewport" content="width=device-width, initial-scale=1.0">\n' +
' <title>404</title>\n' +
' <style> * { max-width: initial !important; } </style>\n' +
'</head>\n' +
'<body style="margin: 0;padding: 0;">\n' +
// ' <div style="width: 100%;height: 100%;">\n' +
// ' <img src="/deleted/skin/4.png" alt="" style="background-size: 100% 100%;background-repeat: no-repeat;width: 100%;height: 100%;">\n' +
// ' </div>\n' +
' <center><h1>404 Not Found</h1></center>\n' +
' <hr><center>nginx</center>\n' +
'</body>\n' +
'</html>');
</script>
{/if}