WordPress 中文文档
Template Tags/previous post
出自WordPress Chinese 中文文档
p style=color:#c00;This function has been deprecated. That means it has been replaced by a new function or is no longer supported, and may be removed from future versions. All code that uses this function should be converted to use its replacement if one exists./p
目录 |
Description
Used on single post/permalink pages, this tag lists the previous post in chronological order from the current post. It can work in conjuntion with the next_post() tag. This tag must be used in The Loop.
For the index, category, and archives templates, use the posts_nav_link() tag.
Replace With
Usage
%%% ?php previous_post('format', 'previous', 'title', 'in_same_cat',
limitprev, excluded_category); ? %%%
Examples
Default Usage
By default, displays text previous post: as link along with post title.
div style=border:1px solid blue; width:50%; padding:10pxprevious post: Previous Post Title/div
%%% ?php previous_post(); ? %%%
Using Text As Link, Without Post Title
Displays specified text as link, without including the post title. If excessively long post titles break your layout, you may want to use this. laquo; Previous is the specified text in this example; you can put whatever you want.
div style=border:1px solid blue; width:50%; padding:10pxlaquo; Previous/div
%%% ?php previous_post('%','laquo; Previous', 'no'); ? %%%
Using Specific Text
Displays previous and next post links in the format with the text before the post title not shown as a link.
div style=border:1px solid blue; width:50%; padding:10pxPrevious: Previous Post Titlenbsp;nbsp;nbsp;nbsp;|nbsp;nbsp;nbsp;nbsp;Next: Next Post Title/div
lt;pgt;?php previous_post('%', 'Previous:', 'no'); ?
| ?php next_post('%', 'Next:', 'no'); ?lt;/pgt;
Using Arrows Not Text
To display text, like arrows (laquo;), at the beginning of the previous post link and at the end of the next post link so it looks like:
div style=border:1px solid blue; width:50%; padding:10pxlaquo; laquo; Previous Post Titlenbsp;nbsp;nbsp;nbsp;|nbsp;nbsp;nbsp;nbsp;Next Post Title raquo; raquo;/div
pre?php previous_post('amp;laquo; amp;laquo; %', , 'yes'); ? | ?php next_post('% amp;raquo; amp;raquo; ', , 'yes'); ?/pre
Parameters
- format
- (string) Format string for the link. tt'%'/tt in string will be replaced with the link, so tt'Go to %'/tt will generate Go to a href=... Defaults to tt'%'/tt.
- previous
- (string) Link text to display. Defaults to tt'previous post: '/tt.
- title
- (string) Indicates whether title should be used as link text. If set to tt'yes'/tt, immediately follows previous (above). Options are:
- tt'yes'/tt (Default)
- tt'no'/tt
- in_same_cat
- (string) Indicates whether the previous post link must be in the same category/categories as current. Parameter works with versions of WordPress 1.5.1.3 and above. If post is listed in more than one category, it will show posts within the parent category, not the child category. Options are:
- tt'yes'/tt
- tt'no'/tt (Default)
- limitprev
- (integer) Sets previous post link on numeric value of parameter (current post ID minus limitprev). Defaults to tt1/tt. Default is recommended.
- excluded_category
- (integer -or- string) Numeric category ID(s) from which the previous post should not be listed. Separate multiple categories with an 'ttand/tt': tt'1 and 5 and 15'/tt. There is no default. Parameter works with versions of WordPress 1.5.2 and above.
Related
See also next_post().
the_ID, the_title, the_title_attribute, single_post_title, the_title_rss, the_content, the_content_rss, the_excerpt, the_excerpt_rss, previous_post_link, next_post_link, posts_nav_link, the_meta,
div style=background: #f7f7f7; border: 1px solid #000; padding: 10px;
How to pass parameters to tags with PHP function-style parameters

