Categories

Easy Post-to-Post Links

Author:Scott Reilly
Version:2.0
Last update:11 April 2008
Compatibility:WP 2.2+, 2.3+ and 2.5+
Comments:go here
Download:[ zip ]
Description:

Easily create a link to another post using a simple shortcut that references the post’s id or slug; the link text is the post’s title, unless overridden.

Extended Description

When writing your posts, you can refer to other posts either by ID, like so:

[post="20"] or <!--post="20"-->

or by the post slug/name, like so:

[post="hello-world"] or <!--post="hello-world"-->.

When viewed on your site, the post-to-post link tag is replaced with a permalink to the post you’ve referenced. By default, the text of the link will be the referenced post’s title, resulting in something like:

<a href="http://example.com/archives/2005/04/01/hello-world/" title="Hello World!">Hello World!</a>

You can optionally customize the link text by specifying a text="" value to the post-to-post link tag:

Check out [post="hello-world" text="my first post"].

Yields:

Check out <a href="http://example.com/archives/2005/04/01/hello-world/" title="Hello World!">my first post</a>.

The HTML comment notation was the original syntax employed by earlier versions of this plugin. While it is still supported, it is no longer the primary and recommended syntax. Instead, use the square-bracket notation. However, you can enable legacy tag support by checking the appropriate option on the plugin’s admin options page.

A quicktag button labeled “post link” is created by default, which will automatically insert [post=""] into the post/page textarea. Insert the ID/post slug between the double-quotes. A visual editor button has also been added which does the same thing as well, which also adds the feature of treating highlighted text as the text="" value when the button is pressed.

The plugin provides its own admin options page via Options → Post2Post (or in WP 2.5: Settings → Post2Post) in the WordPress admin. Here you can define text that you want to appear before and/or after each post-to-post substitution, whether to create the post editor quicktag buttons, and if you want to enable legacy tag support. This admin page also provides some documentation.

NOTE: The HTML comment syntax notation does NOT play well with the visual (aka rich-text) editor in the WordPress admin.

Screenshot

  • A screenshot of the plugin’s admin options page
    screenshot 1

Installation

  1. Download the file post-to-post-links.zip and unzip it into your wp-content/plugins/ directory.
  2. Activate the plugin through the ‘Plugins’ admin menu in WordPress.
  3. Go to the Options → Post2Post (or in WP 2.5: Settings → Post2Post) admin options page. Optionally customize the options.
  4. Use the Post-to-Post link syntax in posts to refer to other posts, as needed. (See examples.)

Examples

These are all valid ways to reference another of your posts on the same blog. Those that use HTML comment notation (i.e. &lt;!-- post="XX" -->) only work if you’ve enabled legacy tag support.

  • [post=25]
  • [post="25"]
  • [post = "25"]
  • [post='25']
  • [post = '25']
  • [post="the-best-post-ever"]
  • [post = "the-best-post-ever"]
  • [post='the-best-post-ever']
  • [post = 'the-best-post-ever']
  • <!--post=25-->
  • <!-- post = 25 -->
  • <!--post="25"-->
  • <!--post = "25" -->
  • <!-- post='25'-->
  • <!-- post = '25' -->

Assuming all of the above were used to reference the same post, the replacement for the post-to-post shortcut would be:

<a href="http://example.com/2008/03/01/the-best-post-ever" title="The Best Post Ever!">The Best Post Ever!</a>

For any of the above you can also optionally specify a text="" value. If so defined, that text will be used as the link text as opposed to the referenced post’s title.

  • [post="25" text="this post"]
  • [post="blog-anniversary" text="Congratulate me!"]
  • <!--post="25" text="this post"-->
  • <!--post='hello-world' text='this post'-->

The first of which would produce:

<a href="http://example.com/2008/03/01/the-best-post-ever" title="The Best Post Ever!">this post</a>

Frequently Asked Questions

  • Q: Should I enable legacy tag support?

    A: The “Enable legacy tag support?” setting controls whether the older, HTML comment style notation should be recognized. You should only enable legacy if you’ve used versions of this plugin prior to v2.0 and still want those post-to-post links to work without updating them. If you started using the plugin at v2.0 or later, you do not need to enable legacy support.

  • Q: What happens when a post-to-post tag references a post that does not exist?

    A: If no post on your blog matches the value you specified as either a post ID or post slug, then the post-to-post tag in question disappears from the view, having been replaced with an empty string.

Release Log

Copyright & Disclaimer

Copyright © 2005-2008 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Acknowledgements

Thanks to all those who have contributed feedback and support!

2 replies on “Easy Post-to-Post Links”

Leave a Reply

Your email address will not be published.