几个常用的TYPECHO模板调用代码
自定义一下标题,以下为代码和参考案例:
1.
<?php
if
(
$this
->_currentPage>1)
echo
'第 '
.
$this
->_currentPage.
' 页 - '
; ?><?php
$this
->archiveTitle(
''
,
''
,
' - '
); ?><?php
$this
->options->title(); ?><?php
if
(
$this
->is(
'index'
)): ?> - 博客首页自定义关键词<?php
endif
; ?>
1.
首页:博客名 - 博客首页自定义关键词
2.
分页:第 2 页 - 博客名 - 博客文字介绍等等
3.
分类:分类名 - 博客名
4.
分页:第 54页 - 分类名 - 博客名
根据TAG调用相关文章:
1.
<?php
$this
->related(5)->to(
$relatedPosts
); ?>
2.
<ul>
3.
<?php
while
(
$relatedPosts
->next()): ?>
4.
<li><a href=
"<?php $relatedPosts->permalink(); ?>"
title=
"<?php $relatedPosts->title(); ?>"
><?php
$relatedPosts
->title(); ?></a></li>
5.
<?php
endwhile
; ?>
6.
</ul>
上一篇与下一篇
1.
<?php
$this
->thePrev(); ?> <?php
$this
->theNext(); ?>
全部文章列表,可应用于归档或网站地图,蜘蛛指引等
1.
<?php
$this
->widget(
'Widget_Contents_Post_Recent'
,
'pageSize=10000'
)->parse(
'<li>{year}-{month}-{day} : <a href="{permalink}">{title}</a></li>'
); ?>
全部标签列表,按照MID排序:
1.
<?php
$this
->widget(
'Widget_Metas_Tag_Cloud'
)
2.
->to(
$taglist
); ?><?php
while
(
$taglist
->next()): ?>
3.
<li><a href=
"<?php $taglist->permalink(); ?>"
title=
"<?php $taglist->name(); ?>"
><?php
$taglist
->name(); ?></a></li>
4.
<?php
endwhile
; ?>
自定义标签数量(就这里面的20),按照文章数量排序:
1.
<?php
$this
->widget(
'Widget_Metas_Tag_Cloud'
,
array
(
'sort'
=>
'count'
,
'ignoreZeroCount'
=> true,
'desc'
=> true,
'limit'
=> 20))->to(
$tags
); ?>
2.
<?php
while
(
$tags
->next()): ?>
3.
<li><a rel=
"tag"
href=
"<?php $tags->permalink(); ?>"
><?php
$tags
->name(); ?></a></li>
4.
<?php
endwhile
; ?>
自定义分类、标签、搜索、首页等文章分页数量,修改 functions.php 文件:
01.
function
themeInit(
$archive
) {
02.
if
(
$archive
->is(
'index'
)) {
03.
$archive
->parameter->pageSize = 10;
// 自定义条数
04.
}
05.
}
06.
或者:
07.
function
themeInit(
$archive
) {
08.
if
(
$archive
->is(
'category'
,
'default'
)) {
09.
$archive
->parameter->pageSize = 10;
// 自定义条数
10.
}
11.
}
调用某分类文章,pageSize是数量,mid是分类号:
1.
<?php
$this
->widget(
'Widget_Archive@index'
,
'pageSize=6&type=category'
,
'mid=47'
)
2.
->parse(
'<li><a href="{permalink}">{title}</a></li>'
); ?>
判断为当前页的第几篇文章,并单独输出代码,可应用于第一篇文章底部广告:
1.
<?php
if
(
$this
->sequence == 0): ?>
2.
//需要的插入
3.
<?php
endif
; ?>
判断是否为首页,输出相关内容:
1.
<?php
if
(
$this
->is(
'index'
)): ?>
2.
//首页输出内容
3.
<?php
else
: ?>
4.
//不是首页输出内容
5.
<?php
endif
; ?>
判断当前分类,输出内容:
1.
<?php
if
(
$this
->category ==
"help"
): ?>
2.
//当前分类为help缩略图,则输出内容。
3.
<?php
endif
; ?>
首页不显示某分类内容:
1.
<?php
while
(
$this
->next()): ?>
2.
<?php
if
(
$this
->category !=
"cateslug"
): ?>
3.
//正常输出循环
4.
<?php
endif
; ?>
5.
<?php
endwhile
; ?>