本文介绍一下Zblog之txcms2模板于SiteNav模板合并的教程,目前将SiteNav的功能合并到天兴工作室的模板中。

1、首先在当前模板的include.php创建一下插件

//标题字体 2017-09-05 16:22:15
function txcms2_Font(){
	global $zbp,$article;
	if(!$article->Metas->djump){
		$article->Metas->djump= '';
	}
	if(!$article->Metas->fweight){
		$article->Metas->fweight= '';
	}
	if(!$article->Metas->fcolor){
		$article->Metas->fcolor= '';
	}
	echo '<div style="margin-left:16%;border-top:1px #ddd dashed;margin-top:-3px;padding-bottom:11px;"></div><label for="meta_djump" class="editinputname" title="开启后只能在文章页点击外链">网址内置</label>
            <input name="meta_djump" style="display:none;" type="text" value="'.$article->Metas->djump.'" class="checkbox">';
    echo '<div id="alias" class="editmod"><label for="meta_fweight" class="editinputname">标题加粗</label>
            <input name="meta_fweight" style="display:none;" type="text" value="'.$article->Metas->fweight.'" class="checkbox"></div>';
    echo '<div id="alias" class="editmod"><label for="meta_fcolor" class="editinputname">颜色</label>
            <input type="text" name="meta_fcolor" value="'.htmlspecialchars($article->Metas->fcolor).'"/><div style="color:#F8BC8B;font-size:12px;padding-top:6px;">↙↗txcms2主题专有设置项</div></div>';
	echo "<link href=\"{$zbp->host}zb_users/theme/txcms2/source/colpick.css\" rel=\"stylesheet\" type=\"text/css\" />
<style>.colpick{left:auto !important;;right:20px !important;}</style>
<script src=\"{$zbp->host}zb_users/theme/txcms2/source/colpick.js\"></script>
<script>
$(function(){
	$('input[name=meta_fcolor]').colpick({
		layout:'hex',
		submit:0,
		onChange:function(hsb,hex,rgb,el,bySetColor) {
			$(el).css('color','#'+hex);
			if(!bySetColor) $(el).val('#'+hex);
		}
	}).keyup(function(){
		$(this).colpickSetColor(this.value);
	});
});
</script>";
}
//网站网址、首页图片、单页图片 Url
function txcms2_Url(){
    global $zbp,$article;
    if(!$article->Metas->alink){
		$article->Metas->alink= '';
	}
	if(!$article->Metas->imgindex){
		$article->Metas->imgindex= '';
	}
	if(!$article->Metas->imgpage){
		$article->Metas->imgpage= '';
	}
	echo '<div id="alias" class="editmod2"><label for="meta_alink" class="editinputname">网址</label> <input type="text" name="meta_alink" value="'.htmlspecialchars($article->Metas->alink).'" placeholder="请填写符合规范的外链网址,如 http://www.yiwuku.com" style="width:50%"></div>';
	echo '<div id="alias" class="editmod2"><label for="meta_imgindex" class="editinputname">首页图片</label> <input type="text" name="meta_imgindex" value="'.htmlspecialchars($article->Metas->imgindex).'" placeholder="网站首页图片,建议宽度800px" style="width:50%"><strong class="upbtn" title="基于UEditor实现上传" style="color:#fff;padding:3px 15px;margin:0 0.5em;background:#3a6ea5;border:1px solid #3399cc;cursor:pointer;">浏览</strong><span style="color:#F8BC8B;font-size:12px">imgindex</span></div>';
	echo '<div id="alias" class="editmod2"><label for="meta_imgpage" class="editinputname">单页图片</label> <input type="text" name="meta_imgpage" value="'.htmlspecialchars($article->Metas->imgpage).'" placeholder="网站单页图片,建议宽度800px" style="width:50%"><strong class="upbtn" title="基于UEditor实现上传" style="color:#fff;padding:3px 15px;margin:0 0.5em;background:#3a6ea5;border:1px solid #3399cc;cursor:pointer;">浏览</strong><span style="color:#F8BC8B;font-size:12px">imgpage</span></div>';
	if ($zbp->CheckPlugin('UEditor')) { 
	    echo '<script type="text/javascript" src="'.$zbp->host.'zb_users/theme/txcms2/plugin/lib.upload.js"></script>';
	}
}

2、修改Zblog当前模板的template文件夹下post-multi.php(分类列表)模板,我将有图则显示{elseif $zbp->Config('txcms2')->lieb=='3'}增加了一些判断:

a.右侧图片增加内容图显示或首页截图显示或单页截图显示

{elseif $zbp->Config('txcms2')->lieb=='3'}
	{if isset($matchContent[1][0])}
<a href="{$article.Url}" title="{$article.Title}" target="_blank"  class="list-tu {if $zbp->CheckPlugin('IMAGE')}{else}noslt{/if}"><img src="{txcms2_FirstIMG($article,160,135)}"  alt="{$article.Title}" /></a>
   	{elseif $article->Metas->imgindex!=""} 
<a href="{$article.Url}" title="{$article.Title}" target="_blank"  class="list-tu {if $zbp->CheckPlugin('IMAGE')}{else}noslt{/if}"><img src="{$article.Metas.imgindex}" alt="{$article.Title}的首页截图"/></a>
{elseif $article->Metas->imgpage!=""}
<a href="{$article.Url}" title="{$article.Title}" target="_blank"  class="list-tu {if $zbp->CheckPlugin('IMAGE')}{else}noslt{/if}"><img src="{$article.Metas.imgpage}" alt="{$article.Title}的单页截图"/></a>
 {/if}
{else}

  b.增加标题加粗、颜色的替换

    <h2><a href="{$article.Url}"{if $article->Metas->fcolor!="" || $article->Metas->fweight==1} style="{if $article->Metas->fweight==1}font-weight:bold;{/if}{if $article->Metas->fcolor!=""}color:{$article->Metas->fcolor};{/if}"{/if} title="{$article.Title}">{$article.Title}</a></h2>
3、修改Zblog当前模板的template文件夹下index-list.php(分类页子目录)模板,我增加了标题是否加粗加色的判断


{foreach GetList($zbp->Config('txcms2')->cmssl,$flid,null,null,null,null,array('has_subcate'=>true))  as $related}
<li><span>{$related.Time('m-d')}</span><i class="fa fa-caret-right"></i><a href="{$related.Url}"{if $related->Metas->fcolor!="" || $related->Metas->fweight==1} style="{if $related->Metas->fweight==1}font-weight:bold;{/if}{if $related->Metas->fcolor!=""}color:{$related->Metas->fcolor};{/if}"{/if} title="{$related.Title}">{$related.Title}</a></li>
{/foreach}
4.修改Zblog当前模板的template文件夹下index-s.php(首页子列表页)模板,我增加里如有链接则跳转的功能,加在<i class="fa fa-caret-right"></i>后面

{if $related->Metas->alink!="" && $related->Metas->djump!=1}
<a href="{$host}go.php?url=http://{$related->Metas->alink}"{if $related->Metas->fcolor!="" || $related->Metas->fweight==1} style="{if $related->Metas->fweight==1}font-weight:bold;{/if}{if $related->Metas->fcolor!=""}color:{$related->Metas->fcolor};{/if}"{/if} target="_blank" title="{$related.Title}">{$related.Title}</a>
{else}
<a href="{$related.Url}"{if $related->Metas->fcolor!="" || $related->Metas->fweight==1} style="{if $related->Metas->fweight==1}font-weight:bold;{/if}{if $related->Metas->fcolor!=""}color:{$related->Metas->fcolor};{/if}"{/if}itle="{$related.Title}">{$related.Title}</a>
{/if}