WordPress.org

Ready to get started?Download WordPress

Plugin Directory

Linkify Posts

Turn a string, list, or array of post IDs and/or slugs into a list of links to those posts.

Template Tags

The plugin provides one template tag for use in your theme templates, functions.php, or plugins.

Functions

  • <?php c2c_linkify_posts($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/slug, or multiple post IDs/slugs defined via an array, or multiple posts IDs/slugs defined via a comma-separated and/or space-separated string

  • $before (optional) To appear before the entire post listing (if posts exist or if 'none' setting is specified)

  • $after (optional) To appear after the entire post listing (if posts exist or if 'none' setting is specified)

  • $between (optional) To appear between posts

  • $before_last (optional) To appear between the second-to-last and last element, if not specified, 'between' value is used

  • $none (optional) 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 c2c_linkify_posts(43); ?>
<?php c2c_linkify_posts("43"); ?>
<?php c2c_linkify_posts("hello-world"); ?>
<?php c2c_linkify_posts("43 92 102"); ?>
<?php c2c_linkify_posts("hello-world whats-cooking"); ?>
<?php c2c_linkify_posts("43,92,102"); ?>
<?php c2c_linkify_posts("hello-world, whats-cooking"); ?>
<?php c2c_linkify_posts("43, 92, 102"); ?>
<?php c2c_linkify_posts("hello-world, 92, whats-cooking"); ?>
<?php c2c_linkify_posts(array(43,92,102)); ?>
<?php c2c_linkify_posts(array("hello-world", "whats-cooking")); ?>
<?php c2c_linkify_posts(array("43","92","102")); ?>
  • <?php c2c_linkify_posts("43 92"); ?>

Outputs something like:

<a href="http://yourblog.com/archive/2008/01/15/some-post">Some Post</a>,
<a href="http://yourblog.com/archive/2008/01/15/another-post">Another Post</a>
  • 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 c2c_linkify_posts(get_post_meta($post->ID, 'Related Posts', true), "Related posts: "); ?>

Outputs something like:

Related posts: <a href="http://yourblog.com/archive/2008/01/15/some-post">Some Post</a>,
<a href="http://yourblog.com/archive/2008/01/15/another-post">Another Post</a>
  • <ul><?php c2c_linkify_posts("43, 92", "<li>", "</li>", "</li><li>"); ?></ul>

Outputs 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 c2c_linkify_posts(""); // Assume you passed an empty string as the first value ?>

Displays nothing.

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

Outputs:

No posts found.

Filters

The plugin exposes one action for hooking.

c2c_linkify_posts (action)

The 'c2c_linkify_posts' hook allows you to use an alternative approach to safely invoke c2c_linkify_posts() in such a way that if the plugin were to be deactivated or deleted, then your calls to the function won't cause errors in your site.

Arguments:

  • same as for c2c_linkify_posts()

Example:

Instead of:

<?php c2c_linkify_posts( "112, 176", 'Posts: ' ); ?>

Do:

<?php do_action( 'c2c_linkify_posts', "112, 176", 'Posts: ' ); ?>

Requires: 2.8 or higher
Compatible up to: 3.8.3
Last Updated: 2013-12-21
Downloads: 1,857

Ratings

4 stars
4 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,1,1