首页 > CMS建站 > Z-Blog > 正文

Z-BlogPHP主题教程(十二)ZBlogPHP主题制作技巧

2021-11-22 13:49:09
字体:
来源:转载
供稿:网友

Z-BlogPHP主题教程(十二)ZBlogPHP主题制作技巧 主题制作技巧 第1张

同分类文章列表调用

{foreach GetList(调用条数,分类ID) as $related}<li><span>{$related.Time('Y-m-d')}</span><a href="{$related.Url}">{$related.Title}</a></li>{/foreach}

获取大目录下的所有文章(包括子目录文章):

{foreach Getlist(调用条数,分类ID,null,null,null,null,array('has_subcate'=>true)) as $related}<li><span>{$related.Time('Y-m-d')}</span><a href="{$related.Url}">{$related.Title}</a></li>{/foreach}

调用其它数据参考php/133.html" target="_blank" style="box-sizing: border-box; color: rgb(160, 206, 78); background-color: transparent; text-decoration: none;">文章标签。

注意:此处需要使用foreach循环中as后面变量名,如案列中使用的$related,如需调用标题则用{$related.Title},而并非是 {$article.Title}。

网站关键词、描述添加

{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 = $zbp->name;

    }

    $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].StaticName}">{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].StaticName}">{/if}

评论数判断

{if $article.CommNums==0}

暂无留言

{elseif $article.CommNums==1}

仅有1条留言

{else}

已有{$article.CommNums}条留言

{/if}

页面判断

{if $type=='index'&&$page=='1'}  /*判断首页*/

{if $type=='category'}  /*判断分类页*/

{if $type=='article'}  /*判断日志页,不含独立页面,{if $article.Type==ZC_POST_TYPE_ARTICLE}(另一方案)*/

{if $type=='page'}  /*判断独立页面*/

{if $type=='author'}  /*判断用户页*/

{if $type=='date'}  /*判断日期页*/

{if $type=='tag'}  /*判断标签页*/

示例:首页和分类列表页分离

在index.php文件里作判断,分离模板。比如:

{if $type=='index'&&$page=='1'} 

{template:c_index}

{else}

{template:c_list}

{/if}

然后新建两个相应的模板文件:c_index.php和c_list.php

随机获得文章中的四张图片中的一张 

适用于多图站点,在模板文件中使用:

{php}

$temp=mt_rand(1,4);

$pattern="/<[img|IMG].*?src=[/'|/"](.*?(?:[/.gif|/.jpg|/.png]))[/'|/"].*?[//]?>/";

$content = $article->Content;

preg_match_all($pattern,$content,$matchContent);

if(isset($matchContent[1][0])) 

$temp=$matchContent[1][0];

else

$temp=$zbp->host."zb_users/theme/$theme/style/images/random/$temp.jpg";

//需要在相应位置放置4张jpg的文件,名称为1,2,3,4

{/php} 

<img src="{$temp}" />

仅显示文字的文章简介调用方法

{SubStrUTF8(TransferHTML($article.Intro,"[nohtml]"),200)}

分类目录面包屑的代码编写

{php}

$html='';

function navcate($id){

global $html;

$cate = new Category;

$cate->LoadInfoByID($id);

$html ='>>  <a href="' .$cate->Url.'" title="查看' .$cate->Name. '中的全部文章">' .$cate->Name. '</a> '.$html;

if(($cate->ParentID)>0){navcate($cate->ParentID);}

}

navcate($article->Category->ID);

global $html;

echo $html;

{/php}

显示相关文章

搜索$article的相关文章(ZC_RELATEDLIST_COUNT选项默认为10)

PHP

$array=GetList($zbp->option['ZC_RELATEDLIST_COUNT'],null,null,null,null,null,array('is_related'=>$article->ID));

在模板中,获取并输出获取到的相关文章代码参考如下

{$array=GetList($zbp->option['ZC_RELATEDLIST_COUNT'],null,null,null,null,null,array('is_related'=>$article->ID));}<ul id="related">{foreach $array as $related}  <li>

  <span class="time">{$related.Time('m-d')}</span>

  <span class="title"><a href="{$related.Url}" title="{$related.Title}">{$related.Title}</a></span>

  </li>{/foreach}</ul>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表