WordPress:Template Tags/previous post link

来自站长百科
Xxf3325讨论 | 贡献2008年6月27日 (五) 11:03的版本 (新页面: == Description == Used on single post permalink pages, this template tag displays a link to the previous post which exists in chronological order from th...)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航、​ 搜索

Description

Used on single post permalink pages, this template tag displays a link to the previous post which exists in chronological order from the current post.

This tag must be used in WordPress:The Loop.

Usage

%%% <?php previous_post_link('format', 'link', in_same_cat,

                        'excluded_categories'); ?> %%%

Examples

Default Usage

Displays link with left angular quote («) followed by the post title of the previous post (chronological post date order). By default, this tag works like previous_post().

[[WordPress:#Examples|« Previous Post Title]]
<?php previous_post_link(); ?>

Bold Post Title As Link

Displays link with previous chronological post's title wrapped in 'strong' tags (typically sets text to bold).

[[WordPress:#Examples|Previous Post Title]]

%%% <?php previous_post_link('%link'); ?> %%%

Text As Link, Without Post Title, Within Same Category

Displays custom text as link to the previous post within the same category as the current post. Post title is not included here. "Previous in category" is the custom text, which can be changed to fit your requirements.

[[WordPress:#Examples|Previous in category]]

%%% <?php previous_post_link('%link', 'Previous in category', TRUE); ?> %%%

Within Same Category, Excluding One

Displays link to previous post in the same category, as long as it is not in category 13 (the category ID #). You can change the number to any category you wish to exclude. Exclude multiple categories by using " and " as a delimiter.

[[WordPress:#Examples|Previous in category]]

%%% <?php previous_post_link('%link', 'Previous in category', TRUE, '13'); ?> %%%

Parameters

format
(string) Format string for the link. This is where to control what comes before and after the link. '%link' in string will be replaced with whatever is declared as 'link' (see next parameter). 'Go to %link' will generate "Go to <a href=..." Put HTML tags here to style the final results. Defaults to '&laquo; %link'.
link
(string) Link text to display. Defaults to previous post's title ('%title').
in_same_cat
(boolean) Indicates whether previous post must be within the same category as the current post. If set to TRUE, only posts from the current category will be displayed. Options are:
  • TRUE
  • FALSE (Default)
excluded_categories
(string) Numeric category ID(s) from which the previous post should not be listed. Separate multiple categories with and; example: '1 and 5 and 15'. There is no default.

Related

See also next_post_link().

模板:Tag Post Tags

模板:PHP Function Tag Footer