simple tags1.1的相关日志功能
星期六, 10月 20th, 2007simple tags1.1提供了一个函数,st_related_posts(””);这个函数可以添加在文章的结尾处,根据这篇文章的tags,来获取与之相同tags的一组文章的标题列表,从而能帮助读者快速的找到相关信息。
在管理后台,即标签-选项中,我们可以复选此功能,但会在主页面,单个文章页面,文章后都会出现这个相关日志列表,那么,怎么自己添加这个函数呢?我们以只在单个文章下添加为例。
一般的主题文件,simple.php控制着单个页面的显示,打开 single.php,找到文章的结尾处添加
<?php st_related_posts(‘number=10&title=&include_page=false&xformat=<a href=”%permalink%” title=”%title% (%date%)”>%title%</a>’); ?>即可。具体的函数值参考下面,或是作者的主页。
而有些不是在single.php下 添加,如我用的k2,是在theloop.php下控制的。
找到
<div class=”entry-content”>
<?php the_content(sprintf(__(’Continue reading \’%s\”, ‘k2_domain’), the_title(”, ”, false))); ?>
<?php wp_link_pages(’before=<p class=”page-links”><strong>’ . __(’Pages:’,’k2_domain’) . ‘</strong>&after=</p>’); ?>
<?php if ((is_single() or is_day()) ) { ?>
<?php st_related_posts(’number=10&title=相关文章&nopoststext=暂时没
有 :(&include_page=false&xformat=<a href=”%permalink%” title=”%title% (%date%)”>%title%</a>’); ?>
<?php } ?>
</div> <!– .entry-content –>
删除线所标志的,即为我添加的。大家可以试试。
函数:
-
<?php st_related_posts(“”); ?>
函数值:
-
‘number’ => 5,
-
‘orderby’ => ‘counter’,
-
‘order’ => ‘DESC’,
-
‘format’ => ‘list’,
-
‘include_page’ => true,
-
‘exclude_posts’ => ”,
-
‘exclude_tags’ => ”,
-
‘title’ => __(‘<h4>Related posts</h4>’, ’simpletags’),
-
‘nopoststext’ => __(‘No related posts.’, ’simpletags’),
-
‘dateformat’ => $this->dateformat,
-
‘xformat’ => __(‘<a href=”%permalink%” title=”%title% (%date%)”>%title%</a> (%commentcount%)’, ’simpletags’)
举例:
We want to show the first 10 related article without title, without pages and without comments count.
-
<?php st_related_posts(‘number=10&title=&include_page=false&xformat=<a href=”%permalink%” title=”%title% (%date%)”>%title%</a>’); ?>
参数说明:
- number
(integer) Number of articles to show - orderby
(string) Key of tags sorting. Valid values are :- counter - (default) by number of common tags (most relevance)
- post_date - by publication’s date
- post_title - by title
- random - random
- order
(string) Order of sorting. Valid values are :- ASC - ascending
- DESC - descending
- format
(string) show tags as non ordered list UL/LI- flat - (Default) Articles are separated with spaces
- list - articles are inside non ordered lists containing class=’related_posts’
- array -articles are inside a PHP array (use it with st_get_related_posts())
- include_page
(boolean) “true” to add pages, “false” only for posts - exclude_posts
(string) Separate articles ID to exclude with commas - exclude_tags
(string) Separate tags ID to exclude with commas - title
(string) Specify the positioned title before the list - nopoststext
(string) Specify the text to show when there is no related post - dateformat
(string) Specify the date format. Same format as PHP date function - xformat
(string) Extended links format. Available Markups :- %post_date% - Replaced by the date of the article
- %post_permalink% - Replaced by the permalink of the link
- %post_title% - Replaced by the title of the article
- %post_comment% - Replaced by the comments count of the article
- %post_tagcount% - Replaced by the number of common tags
- %post_id% - Replaced by the ID of the article
- %post_relatedtags% - Replaced by common tag list
