Wordpress: Posts’ Links by Category
Posts’ links by category is a WordPress plugin that for a single post shows links to next/previous posts for all categories, which the post is assigned to.
Installation
- Put plc.php into [wordpress_dir]/wp-content/plugins
- Go to the WordPress admin interface and activate the plugin
- (For theme Kubrick)
Go to [theme_dir]/[your_theme]/single.php and change current block <div class=”navigation”> to:
<div class="navigation"> <div class="alignleft"><ul>< ?php plc('prev'); ?></ul></div> <div class="alignright"><ul>< ?php plc('next'); ?></ul></div> </div>At the end of your [theme_dir]/[your_theme]/style.css file add these lines:
.navigation ul { margin:0; padding:0; list-style:none; } .alignright { text-align:right; } .alignleft { text-align:left; }
Options
plc( direction, format, prefix, suffix )
- direction: next or prev (required), shows links for next or previous posts;
- format: generated code (default: ‘<li>%prefix%<a href=”%link%”>%category% %title%</a>%suffix%</li>’ ), where:
- %prefix% will be replaced by prefix (only for links to previous posts)
- %link% will be replaced by link to the post
- %category% will be replaced by category name that post at link is assigned to
- %title% will be replaced by title
- %suffix% will be replaced by suffix (only for links to next posts)
- prefix: prefix for links to previous posts (default: ‘« ‘)
- suffix: suffix for links to next posts (default: ‘ »’)
You can use plc() function as many times as you need. Data will be get from DB only once at the first usage.
Examples
1. Show links to previous posts with default options:
<ul>< ?php plc('prev'); ?></ul>
2. Show links to next posts with default options:
<ul>< ?php plc('next'); ?></ul>
3. Show links to next posts as default format without suffix:
<ul>< ?php plc( 'next','<li>%prefix%<a href="%link%">%category%: %title%</a>%suffix%', '', '' ); ?></ul>
or
<ul>< ?php plc( 'next', '<li><a href="%link%">%category%: %title%</a>' ); ?></ul>
4. Show links to previous posts without category name and prefix:
<ul>< ?php plc('prev', '<li><a href="%link%">%title%</a>' ); ?></ul>
5. Show links to next posts with category name before post’s link and suffix - > :
< ?php plc('next', 'Category %category%: <a href="%link%">%title% %suffix%<br />', '', '>' ); ?>
Advanced
You can use plc_get() function to get data from DB. It will by placed at global variable $plc:
$plc = array(
'prev' => array( // previous posts
0 => array( 'link', 'post', 'category name' ),
...
),
'next' => array( // next posts
0 => array( 'link', 'post', 'category name' ),
...
)
)
Changelog
- 0.1 Initial version
August 27th, 2007 at 02:28
I think the latest version of wordpress has caused a bug, now when I make a new page it is shown as “next post” in the base category. Any idea how I could stop that from happening?
August 28th, 2007 at 22:21
What’s “next post” (title of post, link, …) ?
Show the example.
September 17th, 2007 at 02:37
[...] Wordpress: Posts’ Links by Category - WaLLacE.blog Posts’ links by category is a WordPress plugin that for a single post shows links to next/previous posts for all categories, which the post is assigned to. (tags: wordpress plugin navigation) Daily LinksWeitersagen Gelesen: 14 · heute: 14 · zuletzt: 17.09.2007 · Popularity: 1% [...]
December 11th, 2007 at 16:20
can this be used to show the next 5 posts and previous 5 posts?
December 23rd, 2007 at 16:41
Unfortunately it can’t.