站点名称
1<?php $this->options->title() ?>
站点网址
1<?php $this->options ->siteUrl(); ?>
完整路径标题如分享几个Typecho中常用的调用函数
1<?php $this->archiveTitle(array('category' => '分类 %s 下的文章', 'search' => '包含关键字 %s 的文章', 'tag' => '标签 %s 下的文章', 'author' => '%s 发布的文章'), '', ' - '); ?><?php $this ->options->title(); ?>
站点说明
1<?php $this->options->description() ?>
模板文件夹地址
1<?php $this->options->themeUrl(); ?>
导入模板文件夹内的php文件
1<?php $this< /span>->need('.php'); ?>
文章或者页面的作者
1<?php $this->author(); ?>
作者头像
1< ?php $this->author->gravatar('40') ?>
此处输出的完整的img标签,40是头像的宽和高。
该文作者全部文章列表链接
1<?php $this->author->permalink (); ?>
该文作者个人主页链接
1<?php $this->author->url(); ?>
该文作者的邮箱地址
1<?php $this->author->mail(); ?>
后台地址与登陆地址
上一篇与下一篇调用代码
文章最后编辑时间
1<?php echo gmdate('Y-m-d H:i', $this->modified + Typecho_Widget::widget('Widget_Options')->timezone); ?>
当前文章id
1<?php $this->cid(); ?>
调用某分类文章,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 $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->pageNav('上一页', '下一页', '5', '......'); ?>//显示多个页码的
2<?php $this->pageLink('下一页','next'); ?>
3<?php $this->pageLink('上一页'); ?>//只显示上一页下一页
页码显示
1<?php if($this->_currentPage>1) echo '第'.$this->_currentPage.'页'; ?>
2当前页码:<?php if($this->_currentPage>1) echo $this->_currentPage; else echo 1;?>
3总页码:<?php echo ceil($this->getTotal() / $this->parameter->pageSize); ?>
判断是否为首页,输出相关内容
1<?php if ($this->is('index')): ?>
2//首页输出内容
3<?php else: ?>
4//还可以判断is语法
5$this->is('index');
6$this->is('archive');
7$this->is('single');
8$this->is('page');
9$this->is('post');
10$this->is('category');
11$this->is('tag');
12或者
13$this->is('category', 'default');
14$this->is('page', 'start');
15$this->is('post', 1);
16<?php endif; ?>
判断为当前页的第几篇文章,并单独输出内容
文章或页面,评论数目
1<?php $this->commentsNum('No Comments', '1 Comment' , '%d Comments'); ?>
截取部份文章(首页每篇文章显示摘要),350是字数
1<?php $this->excerpt(350, '.. .'); ?>
调用自定义字段
1<?php $this->fields->fieldName ?>
RSS地址
1<?php $this->options->feedUrl(); ?>
获取最新post
1<?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=8&type=category')->parse('<li><a href="{permalink}">{title}</a></li>'); ?>
分类描述
1<?php echo $this->getDescription(); ?>
纯文字分类名称,不带链接
1<?php $this->category(',', false); ?>
获取文章分类列表
1<ul>
2<?php $this->widget('Widget_Metas_Category_List')->parse('<li><a href="{permalink}">{name}</a> ({count})</li>'); ?>
3</ul>
获取某分类post
1<ul>
2<?php
3$this->widget('Widget_Archive@indexyc', 'pageSize=8&type=category', 'mid=1')
4->parse('<li><a href="{permalink}" title="{title}">{title}</a></li>'); ?>
5</ul>
获取最新评论列表
1<ul>
2 <?php $this->widget('Widget_Comments_Recent')->to($comments); ?>
3 <?php while($comments->next()): ?>
4 <li><a href="<?php $comments->permalink(); ?>"><?php $comments->author(false); ?></a>: <?php $comments->excerpt(50, '...'); ?></li>
5 <?php endwhile; ?>
6</ul>
首页获取 最新文章 代码限制条数
1<?php while ($this->next()): ?>
2<?php if ($this->sequence <= 3): ?>
3// html逻辑
4<?php endif; ?>
5<?php endwhile; ?>
最新文章
1<?php $this->widget('Widget_Contents_Post_Recent')->to($post); ?>
2<?php while($post->next()): ?>
3<a href="<?php $post->permalink(); ?>" title="<?php $post->title(); ?>">
4<?php $post->title(25, '...'); ?></a>
5<?php endwhile; ?>
获取最新评论列表第二个版本,只显示访客评论不显示博主也就是作者或者说自己发的评论
1<?php $this->widget('Widget_Comments_Recent','ignoreAuthor=true')->to($comments); ?>
2<?php while($comments->next()): ?>
3<li><a href="<?php $comments->permalink(); ?>"><?php $comments->author(false); ?></a>: <?php $comments->excerpt(50, '...'); ?></li>
4<?php endwhile; ?>
获取文章时间归档
1<ul>
2<?php $this->widget('Widget_Contents_Post_Date', 'type=month&format=F Y')->parse('<li><a href="{permalink}">{date}</a></li>'); ?>
3</ul>
获取标签集合,也就是标签云
1<?php $this->widget('Widget_Metas_Tag_Cloud', 'ignoreZeroCount=1&limit=28')->to($tags); ?>
2<?php while($tags->next()): ?>
3<a href="<?php $tags->permalink(); ?>" class="size-<?php $tags->split(5, 10, 20, 30); ?>"><?php $tags->name(); ?></a>
4<?php endwhile; ?>
输出随机颜色标签云
1<?php $this->widget('Widget_Metas_Tag_Cloud', 'ignoreZeroCount=1&limit=30')->to($tags); ?>
2<ul class="tags-list">
3<?php while($tags->next()): ?>
4<li><a style="color: rgb(<?php echo(rand(0, 255)); ?>, <?php echo(rand(0,255)); ?>, <?php echo(rand(0, 255)); ?>)" href="<?php $tags->permalink(); ?>" title='<?php $tags->name(); ?>'><?php $tags->name(); ?></a></li>
5<?php endwhile; ?>
6<?php else: ?>
7<li><?php _e('没有任何标签'); ?></li>
8<?php endif; ?>
9</ul>
调用该文相关文章列表
1<?php $this->related(5)->to($relatedPosts); ?>
2 <?php if ($relatedPosts->have()): ?> //这句也可以写成 if (count($relatedPosts->stack))
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 <?php else : ?>
7 <li>无相关文章</li>
8 <?php endif; ?>
隐藏head区域的程序版本和模版名称
1<?php $this->header("generator=&template="); ?>
获取读者墙
1<?php
2$period = time() - 999592000; // 時段: 30 天, 单位: 秒
3$counts = Typecho_Db::get()->fetchAll(Typecho_Db::get()
4->select('COUNT(author) AS cnt','author', 'url', 'mail')
5->from('table.comments')
6->where('created > ?', $period )
7->where('status = ?', 'approved')
8->where('type = ?', 'comment')
9->where('authorId = ?', '0')
10->group('author')
11->order('cnt', Typecho_Db::SORT_DESC)
12->limit(25)
13);
14$mostactive = '';
15$avatar_path = 'http://www.gravatar.com/avatar/';
16foreach ($counts as $count) {
17 $avatar = $avatar_path . md5(strtolower($count['mail'])) . '.jpg';
18 $c_url = $count['url']; if ( !$c_url ) $c_url = Helper::options()->siteUrl;
19 $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";
20}
21echo $mostactive; ?>
登陆与未登录用户展示不同内容
导航页面列表调用隐藏特定的页面 这个演示隐藏了album和search两个页面
1<ul>
2<li<?php if($this->is('index')): ?> class="current"<?php endif; ?>><a href="<?php $this->options->siteUrl(); ?>">主页</a></li>
3<?php $this->widget('Widget_Contents_Page_List')->to($pages); ?>
4 <?php while($pages->next()): ?>
5 <?php if (($pages->slug != 'album') && ($pages->slug != 'search')): ?>
6 <li<?php if($this->is('page', $pages->slug)): ?> class="current"<?php endif; ?>><a href="<?php $pages->permalink(); ?>" title="<?php $pages->title(); ?>"><?php $pages->title(); ?></a></li>
7 <?php endif; ?>
8 <?php endwhile; ?>
9</ul>
根据页面类型显示不同内容
判断为首页则显示内容
判断不同页面显示内容
1<?php if ($this->is('index')): ?>
2//首页 显示内容
3<?php elseif ($this->is('post')): ?>
4//文章 显示内容
5<?php else: ?><
6//页面 显示内容
7<?php endif; ?>
这里可以利用<?php elseif ($this->is('函数')): ?>添加其他函数,继续显示不同的内容
获取文章第一张缩略图
1<?php $this->attachments(1)->attachment->url(); ?>
获取缩略图指当前文章第一个附件地址,确保第一附件为图片
1<?php if($this->attachments(1)->attachment->isImage) $this->attachments(1)->attachment->url(); ?>
判断是否为图片,继续输出
- 自定义首页描述description
1<?php if($thisis('index')): ?>
2<?php this->header('description=详细描述内容部分内容,自定义即可。'); ?>
3<?php else:?>
4<?php $this-> header(); ?>
5<?php endif;?>
- 登录与未登录显示不同内容
- Typecho侧边栏不显示博主评论
pageSize=6 显示多少条
1<?php $this->widget('Widget_Comments_Recent','pageSize=6&ignoreAuthor=true')->to($comments); ?>