Typecho博客主题制作常用变量和函数代码之文章列表调用篇

typecho常用的列表的调用代码 堃埜在此整理归纳不仅是文章列表调用

typecho模版代码

开源项目typecho模版基于高度可以定制型让blog也可以是CMS,typecho的轻巧和轻易定制让很多博友爱不释手。本文用于平时制作typecho查询也给希望可以给typecho新人、有需要的人提供便利。如有错拙之处还望海量指出,如果有更简短版望不吝分享。

Typecho模版调用最新文章列表

<h3>最新发表文章</h3>
<ul><?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=6') ->parse('<li><a href="{permalink}" target="_blank">{title}</a></li>'); ?>
</ul>

参数说明:
pageSize=6表示调用6调内容,从新到旧排列,
{permalink}表示文章链接,
{title}表示文章标题。

Typecho模版调用全部分类文章列表

<?php $this->widget('Widget_Metas_Category_List')->to($category); ?>
<?php while($category->next()): ?>
<div class="textlist">
<h3><a href="<?php $category->permalink(); ?>" title="<?php $category->description(); ?>" target="_blank"><?php $category->name(); ?></a></h3>
<ul>
<?php $this->widget("Widget_Archive@$category->mid" ,array('pageSize' => '6' ,'type' => 'category'), "mid= $category->mid")->parse('<li><a href="{permalink}" target="_blank">{title}</a></li>'); ?>
</ul><!--end/.textlist/--></div><?php endwhile; ?>

参数说明:
$category->permalink()分类链接,
$category->name()分类名称,
$category->slug()分类缩略名(通过次函数做出中英名称效果,以上代码没有做演示),
$category->description分类说明,
‘pageSize’ => ‘6’表示调用6调内容,从新到旧排列,
{permalink}表示文章链接,
{title}表示文章标题。

Typecho模版调用最新评论列表

<h3>最新评论</h3>
<?php Typecho_Widget::widget('Widget_Stat')->to($stat); ?>
<ul><?php $this->widget('Widget_Comments_Recent', 'pageSize=6')->to($comments); ?>
<?php while($comments->next()): ?>
     <li><a href="<?php $comments->permalink(); ?>"><?php $comments->author(false); ?></a>:<?php $comments->excerpt(35, '...'); ?></li>
<?php endwhile; ?></ul>

参数说明:
pageSize=6 其中6代表调用6条,$comments->permalink()所评论文章链接,$comments->author(false)发起评论作者名称,$comments->excerpt(35, ‘…’)评论内容摘要(35代表调用字数)

Typecho模版调用特定分类文章列表

<h3>分类名称</h3>
<ul>
<?php  $this->widget('Widget_Archive@indexfenlei', 'pageSize=5&type=category', 'mid=122') ->parse('<li><a href="{permalink}" title="{title}" target="_blank">{title}</a></li>'); ?>
</ul>

参数说明:
不足(分类名称需要手动填写),Widget_Archive@indexqiyue (可以随便@英文字母只要没有重复使用就好),pageSize=5 其中5代表调用该分类输出文章条数,mid=122 其中122代表需要调用分类的ID(后台编辑分类看地址栏)也可以改写为slug=title 其中title代表需要调用分类缩略名,{permalink}分类文章链接,{title}分类文章标题

Typecho模版调用特定标签文章列表

<h3>标签名称</h3>
<ul>
<?php  $this->widget('Widget_Archive@indexbiaoqian', 'pageSize=5&type=tag', 'mid=122') ->parse('<li><a href="{permalink}" title="{title}" target="_blank">{title}</a></li>'); ?>
</ul>

参数说明:
标签文章列表调用和分类文章列表基本一致,不足(标签名称需要手动填写),Widget_Archive@indexqiyue (可以随便@英文字母只要没有重复使用就好),pageSize=5 其中5代表调用该标签输出文章条数,mid=122 其中122代表需要调用标签的ID(后台编辑标签看地址栏)也可以改写为slug=title 其中title代表需要待遇标签的缩略名,{permalink}标签链接,{title}标签名称

给typecho加上焦点图轮播(幻灯片、图片切换)功能效果(非插件)

因为不仅是直接调用所以链接看详情:https://yijile.com/log/365/

Typecho模版调用标签云列表,按多到少排列

<?php $this->widget('Widget_Metas_Tag_Cloud', 'sort=mid&ignoreZeroCount=1&desc=0&limit=30')->to($tags); ?>
<?php if($tags->have()): ?>
<?php while ($tags->next()): ?><a href="<?php $tags->permalink(); ?>" rel="tag"><?php $tags->name(); ?>(<?php $tags->count(); ?>)</a>
<?php endwhile; ?>
<?php else: ?><?php _e('没有任何标签'); ?><?php endif; ?>

参数说明:
limit=30 其中30代表调用30个标签(按文章数多到少导出列表),$tags->permalink()标签链接,$tags->name()标签名称,$tags->count()该标签文章数量,

Typecho模版调用分类列表,也常用作导航调用

<ul>
<li<?php if($this->is('index')): ?> class="current"<?php endif; ?>><a href="<?php $this->options->siteUrl(); ?>"><?php _e('首页'); ?></a></li>
<?php $this->widget('Widget_Metas_Category_List')
            ->parse('<li><a href="{permalink}">{name}<span>{count}</span></li>'); ?> 
</ul>

参数说明:
{permalink}分类链接,{name}分类名称,{slug}分类缩略名(可以做到中英导航效果),{count}分类文章数

Typecho模版调用页面列表,也常用作导航调用

<ul> 
<?php $this->widget('Widget_Contents_Page_List')->to($pages); ?>
<li<?php if($this->is('index')): ?> class="current"<?php endif; ?>><a href="<?php $this->options->siteUrl(); ?>"><?php _e('首页'); ?></a></li>
<?php while($pages->next()): ?>
    <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>
<?php endwhile; ?>
</ul>

参数说明:
class=”current”当前页面该链接特殊样式,permalink(); ?>页面地址,title(); ?>页面标题,slug(); ?>页面缩略名(可以做到中英导航效果)

Typecho模版调用读者列表,非缓存图像本地化版本

<h3>读者风云榜</h3>
<ul class="float-no">
<?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('24')
);
$mostactive = '';
$avatar_path = 'http://cn.gravatar.com/avatar/';
foreach ($counts as $count) {
  $avatar = $avatar_path . md5(strtolower($count['mail'])) . '.jpg?s=96';
  $c_url = $count['url']; if ( !$c_url ) $c_url = Helper::options()->siteUrl;
  $mostactive .= "<li><a href='" . $c_url . "' title='" . $count['author'] . " (参与" . $count['cnt'] . "次探讨)' rel='nofollow' target='_blank'><img src='" . $avatar . "' alt='" . $count['author'] . "的照片' class='avatar' /><small>" . $count['author'] . "</small><i>" . $count['cnt'] . "</i></a></li>\n";
}
echo $mostactive; ?></ul> 

参数说明:
主要几个参数:limit(‘24’)调用显示多少位读者,http://cn.gravatar.com/avatar/中国镜像(cn中国、www/0/en应该都是美国吧),.jpg?s=96 其中96表示输出图像宽和高(单位px),$c_url网站链接,$count[‘author’]名字,$avatar输出头像地址(基于Gravatar),$count[‘cnt’]评论总次数,rel=’nofollow’搜索引擎不追踪。。。

Typecho模版基于插件的列表调用

Typecho模版调用最多点击的文章列表

<h3>最新发表文章</h3>
<ul>
<?php Views_Plugin::theMostViewed(); ?>
</ul>

参数说明:
基于【Views】插件,【Plugin.php】文件大概115行始可以定制修改输出效果,按逻辑讲应该可以模版调用定制而不修改插件源码,因为不是很必要,这里就不折腾。

Typecho模版调用友情链接列表

<h3>友情链接</h3> 
<ul>
<?php Links_Plugin::output("SHOW_MIX"); ?>
</ul>

参数说明:
基于【link】插件,SHOW_MIX表示调用纯文字友情链接列表,SHOW_IMG表示调用纯logo图像友情链接列表,在修改以及乐模板时根据需求堃埜做了下面那些补充

<h4 class="module-title"><strong>博友圈</strong></h4> 
<ul>
<?php Links_Plugin::output("SHOW_ITD"); ?>
</ul>

SHOW_ITD需要修改插件,堃埜在【link】插件【Plugin.php】9.0版文件大概264行”}”的位置后面增加了以下代码然后调用出来显示顺序是LOGO图像、网站名称、简介说明,默认版简介说明是在title标签中需要鼠标移动到链接上才显示。SHIW_ITD可以做得直接显示,其命名也就是根据image(图像)title(标题)description(说明)而定为ITD

 else if ($pattern == "SHOW_ITD") {
            $pattern = "<li><a href=\"{url}\" title=\"{title}\" target=\"_blank\"><img src=\"{image}\" alt=\"{name}\" /><strong>{name}</strong><em>{title}</em></a></li>\n";
        }

{url}网站链接,{title}网站说明、{image}网站图像、{name}网站名称

没察觉,整理这些零散的片段花了堃埜几个小时,或许不是最完美的代码集,但是基本算最完整的列表调用吧。

Relay Tips: 一极乐https://yijile.com/log/363/