0 error zblog php添加网站关键词、描述的代码

zblog教程 1794

zblog官方网站提供了php版本zblog网站的首页、文章、页面和其它页面的标题Title、关键词Keywords和描述Description的添加代码,但在制作主题的时候发现,官方提供的代码会生成error错误,博客吧经过使用zbpdk插件,开启zblog调试模式找到相关错误位置,对会生成error的地方进行了代码修改。

官方提供的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{if $type=='article'}
  <title>{$title}_{$article.Category.Name}_{$name}</title>
  {php}
    $aryTags = array();
    foreach($article->Tags as $key){
      $aryTags[] = $key->Name;
    }
    if(count($aryTags)>0) $keywords = implode(',',$aryTags);
    $description = preg_replace('/[\r\n\s]+/', ' ', trim(SubStrUTF8(TransferHTML($article->Content,'[nohtml]'),135)).'...');
  {/php}
  <meta name="keywords" content="{$keywords}"/>
  <meta name="description" content="{$description}"/>
  <meta name="author" content="{$article.Author.StaticName}">
{elseif $type=='page'}
  <title>{$title}_{$name}_{$subname}</title>
  <meta name="keywords" content="{$title},{$name}"/>
  {php}
    $description = preg_replace('/[\r\n\s]+/', ' ', trim(SubStrUTF8(TransferHTML($article->Content,'[nohtml]'),135)).'...');
  {/php}
  <meta name="description" content="{$description}"/>
  <meta name="author" content="{$article.Author.StaticName}">
{elseif $type=='index'}
  <title>{$name}{if $page>'1'}_第{$pagebar.PageNow}{/if}_{$subname}</title>
  <meta name="Keywords" content="自定义关键词,{$name}">
  <meta name="description" content="自定义描述_{$name}_{$title}">
  <meta name="author" content="{$zbp.members[1].Name}">
{else}
  <title>{$title}_{$name}_第{$pagebar.PageNow}</title>
  <meta name="Keywords" content="{$title},{$name}">
  <meta name="description" content="{$title}_{$name}_当前是第{$pagebar.PageNow}页">
  <meta name="author" content="{$zbp.members[1].Name}">
{/if}

修改后的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{if $type=='article'}
	<title>{$title}_{$article.Category.Name}_{$name}</title>
	{php}
    $aryTags = array();
    foreach($article->Tags as $key){
      $aryTags[] = $key->Name;
    }
    if(count($aryTags)>0) 
        $keywords = implode(',',$aryTags);
    else
        $keywords = '';
    $description = preg_replace('/[\r\n\s]+/', ' ', trim(SubStrUTF8(TransferHTML($article->Content,'[nohtml]'),135)).'...');
	{/php}
	<meta name="keywords" content="{$keywords}"/>
	<meta name="description" content="{$description}"/>
	<meta name="author" content="{$article.Author.StaticName}"/>
{elseif $type=='page'}
	<title>{$title}_{$name}_{$subname}</title>
	<meta name="keywords" content="{$title},{$name}"/>
	{php}
    $description = preg_replace('/[\r\n\s]+/', ' ', trim(SubStrUTF8(TransferHTML($article->Content,'[nohtml]'),135)).'...');
	{/php}
	<meta name="description" content="{$description}"/>
	<meta name="author" content="{$article.Author.StaticName}"/>
	{elseif $type=='index'}
	<title>{$name}{if $page>'1'}_第{$pagebar.PageNow}{/if}_{$subname}</title>
	<meta name="Keywords" content="{digital_Require('keywords.txt')}"/>
	<meta name="description" content="{digital_Require('description.txt')}"/>
	<meta name="author" content="{$zbp.members[1].Name}"/>
{else}
	<title>{$title}_{$name}{if $page>'1'}_第{$pagebar.PageNow}{/if}</title>
	<meta name="Keywords" content="{$title},{$name}"/>
	<meta name="description" content="{$title}_{$name}{if $page>'1'}_当前是第{$pagebar.PageNow}页{/if}"/>
	<meta name="author" content="{$zbp.members[1].Name}"/>
{/if}

请博主们自主选择官方的代码还是博客吧修改后的代码!

精品推荐: