Typecho主题模版常用调用变量和函数,参数收集
大部分都从网上搜刮整理的,有些小部分是我自己针对我用的主题乱瞎弄的,不一定所有的主题都100%可以用!Typecho正式版本1.1亲试有效!
随机背景颜色标签云
这个是针对防黑色字体看不清的背景颜色,官方的标签文档说明!
<?php $this->widget('Widget_Metas_Tag_Cloud', 'ignoreZeroCount=1&limit=30')->to($tags); ?>
<ul class="tags-list">
<?php while($tags->next()): ?>
<li><a style="background-color: rgb(<?php echo(rand(40, 255)); ?>, <?php echo(rand(90,255)); ?>, <?php echo(rand(150, 255)); ?>)" href="<?php $tags->permalink(); ?>" title='<?php $tags->name(); ?>'><?php $tags->name(); ?></a></li>
<?php endwhile; ?>
</ul>
站点名称
<?php $this->options->title(); ?>
域名地址
<?php $this->options->siteUrl(); ?>
站点说明
<?php $this->options->description(); ?>
完整路径标题,比如 文章 站点
<?php $this->archiveTitle(' » ', '', ' - '); ?><?php $this->options->title(); ?>
后台地址
<?php $this->options->adminUrl(); ?>
模版文件夹地址
<?php $this->options->themeUrl(); ?>
作者名字
<?php $this->author(); ?>
当前登陆用户名字
<?php $this->user->screenName(); ?>
退出链接
<a href="<?php $this->options->logoutUrl(); ?>"><?php _e('退出'); ?></a>
rss地址
<?php $this->options->feedUrl(); ?>
rss评论
<?php $this->options->commentsFeedUrl(); ?>
作者头像
此函数是完整 img 标签,数字80代表输出头像大小长和宽
<?php $this->author->gravatar('80') ?>
该文作者全部文章列表链接
<?php $this->author->permalink(); ?>
该文作者个人主页链接
<?php $this->author->url(); ?>
该文作者的邮箱地址
<?php $this->author->mail(); ?>
引用模版文件夹内php文件
可以使用相对路径获取上级目录php文件
<?php $this->need('*.php'); ?>
获取最新post
<?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=8&type=category')->parse('<li><a href="{permalink}">{title}</a></li>'); ?>
纯文字分类名称,不带链接
<?php $this->category(',', false); ?>
获取文章分类列表
比如用在菜单
<ul>
<?php $this->widget('Widget_Metas_Category_List')
->parse('<li><a href="{permalink}">{name}</a> ({count})</li>'); ?>
</ul>
获取某分类post
注意mid取值
<ul>
<?php
$this->widget('Wi[email protected]', 'pageSize=8&type=category', 'mid=1')
->parse('<li><a href="{permalink}" title="{title}">{title}</a></li>'); ?>
</ul>
获取最新评论列表
<ul>
<?php $this->widget('Widget_Comments_Recent')->to($comments); ?>
<?php while($comments->next()): ?>
<li><a href="<?php $comments->permalink(); ?>"><?php $comments->author(false); ?></a>: <?php $comments->excerpt(50, '...'); ?></li>
<?php endwhile; ?>
</ul>
获取最新评论列表不显示博主
只显示访客评论不显示博主,也就是作者或者说自己发的评论
<?php $this->widget('Widget_Comments_Recent','ignoreAuthor=true')->to($comments); ?>
<?php while($comments->next()): ?>
<li><a href="<?php $comments->permalink(); ?>"><?php $comments->author(false); ?></a>: <?php $comments->excerpt(50, '...'); ?></li>
<?php endwhile; ?>
首页获取最新文章代码限制条数
现在最新版本1.1 (17.10.30),后台:设置-阅读-每页文章数目!
<?php while ($this->next()): ?>
<?php if ($this->sequence <= 3): ?>
html
<?php endif; ?>
<?php endwhile; ?>
获取文章时间归档
<ul>
<?php $this->widget('Widget_Contents_Post_Date', 'type=month&format=F Y')
->parse('<li><a href="{permalink}">{date}</a></li>'); ?>
</ul>
文章循环
<?php while($this->next()): ?>
<!--文章标题内容等-->
<?php endwhile; ?>
调用该文相关文章列表
好像是根据标签判断相关
<?php $this->related(5)->to($relatedPosts); ?>
<?php if ($relatedPosts->have()): ?> //这句也可以写成 if (count($relatedPosts->stack))
<?php while ($relatedPosts->next()): ?>
<li><a href="<?php $relatedPosts->permalink(); ?>" title="<?php $relatedPosts->title(); ?>"><?php $relatedPosts->title(); ?></a></li>
<?php endwhile; ?>
<?php else : ?>
<li>无相关文章</li>
<?php endif; ?>
各种列表页面标题,如标签分类
<?php $this->archiveTitle(' ', '', ''); ?
文章或页面,标题
<?php $this->title() ?>
文章上下一篇
最新为上,旧为下,时间排序类推!(网站文章上下一篇关联使用逻辑)
上一篇:<?php $this->theNext(); ?>
下一篇:<?php $this->thePrev(); ?>
文章或页面,链接
<?php $this->permalink() ?>
文章或页面,发表时间
<?php $this->date(); ?>
文章或页面,评论数目
<?php $this->commentsNum('No Comments', '1 Comment', '%d Comments'); ?>
文章或页面阅读剩余部分more
文章或页面,内容,括号里有内容,如果加入了more就会自动生成链接
<?php $this->content('阅读剩余部分...'); ?>
文章所在分类,链接形式
<?php $this->category(','); ?>
文章,所加标签
<?php $this->tags(', ', true, 'none'); ?>
列表页分页
<?php $this->pageNav(); ?>
示例:
示例1:
<?php $comments->pageNav('上一页','下一页'); ?>
示例2:
<?php $comments->pageNav('上一页', '下一页', 0, '..'); ?>
隐藏head区域程序版本和模版名称
彻底删除Typecho模版中程序版本号、模版名称等多余Meta标签
<?php $this->header("generator=&template="); ?>
获取读者墙
<?php
$period = time() - 999592000; // 時段: 30 天, 單位: 秒
$counts = Typecho_Db::get()->fetchAll(Typecho_Db::get()
->select('COUNT(author) AS cnt','author', 'url', 'mail')
->from('table.comments')
->where('created > ?', $period )
->where('status = ?', 'approved')
->where('type = ?', 'comment')
->where('authorId = ?', '0')
->group('author')
->order('cnt', Typecho_Db::SORT_DESC)
->limit(25)
);
$mostactive = '';
$avatar_path = 'http://www.gravatar.com/avatar/';
foreach ($counts as $count) {
$avatar = $avatar_path . md5(strtolower($count['mail'])) . '.jpg';
$c_url = $count['url']; if ( !$c_url ) $c_url = Helper::options()->siteUrl;
$mostactive .= "<a href='" . $c_url . "' title='" . $count['author'] . " (参与" . $count['cnt'] . "次互动)' target='_blank'><img src='" . $avatar . "' alt='" . $count['author'] . "的头像' class='avatar' width='32' height='32' /></a>\n";
}
echo $mostactive; ?>
登陆与未登录用户展示不同内容
<?php if($this->user->hasLogin()): ?>
登陆可见
<?php else: ?>
未登录和登陆均可见
<?php endif; ?>
Typecho归档页面
<?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=10000')->to($archives);
$year=0; $mon=0; $i=0; $j=0;
$output = '<div id="archives">';
while($archives->next()):
$year_tmp = date('Y',$archives->created);
$mon_tmp = date('m',$archives->created);
$y=$year; $m=$mon;
if ($mon != $mon_tmp && $mon > 0) $output .= '</ul></li>';
if ($year != $year_tmp && $year > 0) $output .= '</ul>';
if ($year != $year_tmp) {
$year = $year_tmp;
$output .= '<h3 class="al_year">'. $year .' 年</h3><ul class="al_mon_list">'; //输出年份
}
if ($mon != $mon_tmp) {
$mon = $mon_tmp;
$output .= '<li><span class="al_mon">'. $mon .' 月</span><ul class="al_post_list">'; //输出月份
}
$output .= '<li>'.date('d日: ',$archives->created).'<a href="'.$archives->permalink .'">'. $archives->title .'</a> <em>('. $archives->commentsNum.')</em></li>'; //输出文章日期和标题
endwhile;
$output .= '</ul></li></ul></div>';
echo $output;
?>
前台编辑文章
判断登录用户的用户组(管理员,博主),链接规则:http://10086.re/admin/write-post.php?cid=113
代码放到主题post.php文件(文章内容页面),我是直接放在文章标题下的。
<?php $currGroup = get_object_vars($this->user) ['row']['group'];if ($currGroup == "administrator"): ?>
<a href="<?php $this->options->adminUrl('write-post.php?cid=' . $this->cid ); ?>" target="_blank">编辑</a>
<?php endif; ?>
文章列表不输出全文
Typecho的文章撰写里面可以使用<!–more–>来控制首页或者分类文章列表显示文章的内容,但有时候码完字后忘记添加了又需要进去编辑添加。为了能达到一劳永逸的效果,以下将采用修改Typecho模版来实现全局控制文章显示的内容。
只输出文章里面的中第一个块级元素中的内容
<?php $this->summary(); ?>
输出字节不控制
<?php $this->excerpt(); ?>
局控制文章显示文字数量(200)
<?php $this->excerpt(200, '...'); ?>
默认
<?php $this->content('阅读剩余部分...'); ?>
Typecho文章更新时间
最后更新:<?php echo date('Y年m月d日', $this->modified);?>
文章目录
- 随机背景颜色标签云
- 站点名称
- 域名地址
- 站点说明
- 完整路径标题,比如 文章 站点
- 后台地址
- 模版文件夹地址
- 作者名字
- 当前登陆用户名字
- 退出链接
- rss地址
- rss评论
- 作者头像
- 该文作者全部文章列表链接
- 该文作者个人主页链接
- 该文作者的邮箱地址
- 引用模版文件夹内php文件
- 获取最新post
- 纯文字分类名称,不带链接
- 获取文章分类列表
- 获取某分类post
- 获取最新评论列表
- 获取最新评论列表不显示博主
- 首页获取最新文章代码限制条数
- 获取文章时间归档
- 文章循环
- 调用该文相关文章列表
- 各种列表页面标题,如标签分类
- 文章或页面,标题
- 文章上下一篇
- 文章或页面,链接
- 文章或页面,发表时间
- 文章或页面,评论数目
- 文章或页面阅读剩余部分more
- 文章所在分类,链接形式
- 文章,所加标签
- 列表页分页
- 隐藏head区域程序版本和模版名称
- 获取读者墙
- 登陆与未登录用户展示不同内容
- Typecho归档页面
- 前台编辑文章
- 文章列表不输出全文
- Typecho文章更新时间
网站统计:
这玩意儿做和改typecho模版必备哇