I just completed 14 Days of WordPress Plugins + 7 Bonus Plugins!

Linkify Post IDs

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

Turn a list of post IDs into a list of links to those posts.

Extended Description

Particularly handy when used in conjunction with the post custom field feature of WordPress. You could define a custom field for “Related Posts” or “Additional Products” and manually list out post IDs, then utilize the function provided by this plugin to display links to those posts in a custom manner.

Installation

  1. Download the file linkify-post-ids.zip and unzip it into your wp-content/plugins/ directory.
  2. Activate the plugin through the ‘Plugins’ admin menu in WordPress.
  3. Use the linkify_post_ids() template tag in one of your templates (be sure to pass it at least the first argument indicating what post IDs to linkify — the argument can be an array, a space-separate list, or a comma-separated lists). Other optional arguments are available to customize the output.

Template Tag

The plugin provides one optional template tag for use in your theme templates.

Function

<?php linkify_post_ids($posts, $before = '', $after = '', $between = ', ', $before_last = '', $none = '') ?>
Displays links to each of any number of posts specified via post IDs

Arguments

  • $posts

    A single post ID, or multiple post IDs defined via an array, or multiple posts IDs defined via a comma-separated and/or space-separated string

  • $before

    Optional argument. Text to appear before the entire post listing (if posts exist or if ‘none’ setting is specified).

  • $after

    Optional argument. Text to appear after the entire post listing (if posts exist or if ‘none’ setting is specified).

  • $between

    Optional argument. Text to appear between all posts.

  • $before_last

    Optional argument. Text to appear between the second-to-last and last element, if not specified, ‘between’ value is used .

  • $none

    Optional argument. Text to appear when no posts have been found. If blank, then the entire function doesn’t display anything.

Examples

  • These are all valid calls:

    
    <?php linkify_post_ids(43); ?>
    <?php linkify_post_ids("43"); ?>
    <?php linkify_post_ids("43 92 102"); ?>
    <?php linkify_post_ids("43,92,102"); ?>
    <?php linkify_post_ids("43, 92, 102"); ?>
    <?php linkify_post_ids(array(43,92,102)); ?>
    <?php linkify_post_ids(array("43","92","102")); ?>
    
  • <?php linkify_post_ids("43 92"); ?>

    Displays something like:

    Some Post,
    Another Post

Assume that you have a custom field with a key of “Related Posts” that happens to have a value of “43 92″ defined (and you’re in-the-loop).

  • <?php linkify_post_ids(get_post_meta($post->ID, 'Related Posts', true), "Related posts: "); ?>

    Displays something like:

    Related posts: Some Post,
    Another Post

  • <ul><?php linkify_post_ids("43, 92", "<li>", "</li>", "</li><li>"); ?></ul>

    Displays something like:

    
    <ul><li><a href="http://yourblog.com/archive/2008/01/15/some-post">Some Post</a></li>
    <li><a href="http://yourblog.com/archive/2008/01/15/another-post">Another Post</a></li></ul>
    
  • <?php linkify_post_ids(""); // Assume you passed an empty string as the first value ?>

    Displays nothing.

  • <?php linkify_post_ids("", "", "", "", "", "No posts found."); // Assume you passed an empty string as the first value ?>

    Displays:
    No posts found.


Release Log


Copyright & Disclaimer

Copyright © 2007-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!