Post-to-Post Links II – A WordPress Plugin For Making Links
Using the Post-to-Post Links II shortcode in your posts and pages, you can create links to other posts, pages, tags, or categories on your WordPress site. You use the ID number or the slug to identify the post, page, tag, or category for your link. The link will use its title as the link text, or you can supply your own link text.
It makes linking within your site more convenient, and it means your links won’t break if you ever change your permalink structure or change the parent-child relationships of your categories.
This plugin was inspired by the Easy Post-to-Post Links plugin written (but no longer maintained by) Scott Reilly. Post-to-Post Links II cannot interpret the old Easy Post-to-Post Links tags, but you may be able to convert your old tags – see below.
If you also install the Koumpounophobia plugin, you will get a Post-to-Post Links II button added to your HTML Editor. You can use it to more easily add the Post-to-Post Links II shortcode to your post (it’ll give you a modal dialog form where you can provide all the values for the shortcode).
Post-to-Post Links II is internationalized, and currently included a Russian translation, courtesy of Fatcow. Please contribute a translation if you can – here’s how.
Help!
Please use the comments section in my most recent blog post about Post to Post Links II for questions.
Installation
Download the zip file, unzip it, and copy the “post-to-post-links-ii” folder to your plugins directory. Then activate it from your plugin panel. After successful activation, you can start using the shortcode. Post-to-Post Links II will appear in your “Settings” menu (but the only thing there is an uninstall option).
If you have Koumpounophobia installed, a Post-to-Post Links button will automatically appear in your HTML Editor after Post-to-Post Links II is activated.
Using the Shortcode
Here are some examples of the shortcode:
A link to the post or page with ID 53 – the title will be used as the link text:
[p2p type="id" value="53"]
A link to the post or page with the slug “hello-world”; the link text will be “read my Hello World post” and page will open in a new window:
[p2p type="slug" value="hello-world" text="read my Hello World post" attributes="target='_blank'"]
A link to the page for the “Travel” category; the link text will be “read all my travel posts”:
[p2p type="cat_slug" value="travel" text="read all my travel posts"]
Possible values for “type” are:
- slug: a post or page slug
- id: a post or page ID number
- cat_slug: a category slug
- cat_id: a category ID number
- tag_slug: a tag slug
- tag_id: a tag ID number
The “value” attribute is either the slug or ID number of the linked post, page, category, or tag.
The “text” attribute provides the text for the link. It’s optional – if you leave it out, the title of the linked post, page, tag, or category will be used.
“attributes” is optional, and allows you to provide any other attributes you’d like for the link, such as a target, title, onclick, etc. Note that you need to use single quotes here, since the value itself is delimited by double quotes.
Converting old Easy Post-to-Post Links Tags
If you used the Scott Reilly’s Easy Post-to-Post Links plugin as much as I did, you’ll want to convert its tags for use with Post-to-Post Links II. Doing so requires 1. you to be comfortable running a SQL query and 2. that you consistently used only post slugs or only IDs with Scott’s plugin. If you used IDs in some tags and slugs in others, then you can’t make the conversion (as there’s nothing in the syntax of Scott’s tag itself that indicates whether you’re linking by ID or slug).
These are the steps:
- Make a backup of your WordPress database, or at least the wp_posts table. This is very important, in case you make a mistake in the SQL.
- Run this SQL statement if you always used slugs for your links:
update wp_posts set post_content = replace(post_content,'[post=','[p2p type="slug" value=');
Or run this SQL statement if you always used IDs for your links:
update wp_posts set post_content = replace(post_content,'[post=','[p2p type="id" value=');
I use the “text” attribute the same way Scott did, so that portion of the tag will carry over seamlessly in the conversion.
Change Log
- 0.2
- added tag_slug and tag_id options
- fixed cat_slug
- fixed localization
- updated button_dialog.html to conform with Kphobia 0.2 specs
- 0.1 – Beta release


