Plugin: Easy Post-to-Post Links

This plugin has been updated! Comments to this post are now closed. For the latest download, documentation, and link for posting new comments related to this plugin, visit the plugin’s new homepage at:
coffee2code.com/wp-plugins/easy-post-to-post-links
Name:
Easy Post-to-Post Links
Author:
Scott Reilly
Version:
0.9
Last updated:
23 March 2005
Description:

Easily reference another post in your blog using a shortcut, either by id or post slug. The shortcut is replaced with the hyperlinked title of the referenced post.

Notes:

There are two type of post-to-post links you can do.

  1. By post ID: e.g. <!--post="24"-->, where 24 is the ID of the post being referenced.
  2. By post slug: e.g. <!---post="hello-world"-->, where hello-world is the slug/post-name of the post being referenced.

By default the plugin creates a quicktag button by the name of “post link” which, when pressed inserts <!--post=""--> at the current cursor position in the post content input field; you must supply either the ID or the post slug for the post you intend to reference.

You can disable the quicktag button from being created by changing the value of the setting $make_quicktag_button

The hyperlinked post title of the referenced post that is put in place of the shortcut is by default prepended and appended with double-quotes. You can reconfigure what text is prepended and what text is appended to the hyperlinked title by modifying appropriate values in the configuration section of the plugin file.

NOTE: An incorrect substitution will take place if you happen to have a post with a numerical title (and thus a numerical post slug). So if you have a post titled “22”, and you attempt <!--post="22"-->, the plugin will link to the post with the ID of 22, which is likely not the one titled 22. In such a case, you would need to reference that post’s ID.

Installation:
  1. Download the file post-to-post-links.zip and unzip it into your /wp-content/plugins/ directory.
    -OR-
    Copy and paste the the code ( post-to-post-links.phps ) into a file called post-to-post-links.php, and put that file into your /wp-content/plugins/ directory. Please ensure you do not introduce any spaces or other characters before the <?php or after the ?>
  2. Optional: Change configuration options in the file to your liking. In-code comments should help you there.
  3. Activate the plugin from your WordPress admin ‘Plugins’ page.
Functions:

function c2c_post_to_post_link ( $text )

  • $text : Text to be scanned for shortcut links to posts
Tips & Examples:

(See notes section above)

Release Log:
  • 23 Mar 2005 : v0.9 — Released to the public
Copyright & Disclaimer:

Copyright (c) 2005 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:
N/A

19 thoughts on “Plugin: Easy Post-to-Post Links

  1. I tested this plugin on a new test blog I created and I ran across a problem (the test blog’s URL is www.tim-weston.com/test/).

    On the main page of the blog, there is a post that tests the plugin and it works fine. If you click on the link to go to the posts permalink, the plugin also works fine.

    But, if you edit the URL so it only has yyyy/mm/dd/, the plugin doesn’t work. Also, if you remove dd/ and/or mm/dd/ the plugin doesn’t work.

    I looked briefly at the code, but I’m not very familiar with how WP plugins work, so I couldn’t figure out what was causing the problem.

  2. I’m having 50% — which I’ll take at the moment.

    This seems to work dandy with numeric values, that is, post ID’s, but does not appear to work for the slugs.

    Definitely would prefer using slugs (post_name) over ID, but heck, it’s version 0.9, hopefully one-dot-oh is in the offing.

  3. OK, that was an easy fix.

    In the plugin function ” c2c_post_to_post_link” on about line 74 or 75, there’s a regex that explicity tosses out slugs that contain the dash character. While this might be cool for the beginning of the slug, i happen to use lots of slugs that contain dashes, so i just changed the regex to this:

    
    function c2c_post_to_post_link( $text ) {
      return preg_replace(
      "#()#ismeU",
      "c2c_post_to_post_link_handler(\"$2\")",
      $text
      );
    
    

    If this helps anyone else cool, and thanks to Scott for a cool, useful plugin.

  4. Wonderful little function, I only have one question I’d like to ask regarding it….I hope thats not too much trouble.

    Would there be a way to include your own custom text to replace the title of the post you’re referencing to? … For example:

    would produce the desired link to the article with the text “and the world is round” highlighted with the link?

    On your site, also, you have , just thought i’d point that out if its a spelling mistake or you need to include that extra -.

    I have included my email address along with this comment so you may contact me on that, I’ll also be checking back for any further comments, I hope this can be done :)

  5. oh dear, some code didnt show up, let me include the blanks:

    On my 3rd paragraph, where it starts with “would”, the following line should be before that.

    on my 5th paragraph, where it says “you have ,” there should be this piece of text before the ,:

  6. I’ve given this plugin a shot and it doesn’t work the way it says it will. I’m using the newest version of WordPress and have followed the instructions exactly, however, it only works if I use the post ID, using post slug will not work whatsoever, also no matter the set up in the code it does not add a quicktag either. Any ideas anyone? I’ve tested it out pretty thoroughly, can’t figure anything out………

Comments are closed.