Friday, September 10, 2010

Wordpress – external link to an article

January 26, 2010 by admin · Leave a Comment 

Ever wanted to put the link to your article title to another site? If so .. you have c0med to the right place.

All you have to do is add the following code to functions.php:


function print_post_title() {

global $post;

$thePostID = $post->ID;

$post_id = get_post($thePostID);

$title = $post_id->post_title;

$perm = get_permalink($post_id);

$post_keys = array(); $post_val = array();

$post_keys = get_post_custom_keys($thePostID);

if (!empty($post_keys)) {

foreach ($post_keys as $pkey) {

if ($pkey=='title_url') {

$post_val = get_post_custom_values($pkey);

}

}

if (empty($post_val)) {

$link = $perm;

} else {

$link = $post_val[0];

}

} else {

$link = $perm;

}

echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>';

}

After you do this you must change everywhere is  <php the_permalink ()?> with <?php print_post_title ()?>.

When you want to do this you must add a field named title_url with the link where you what your post to go.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • Netvibes
  • Reddit
  • RSS
  • Suggest to Techmeme via Twitter
  • Tumblr
  • Twitter
  • Twitthis
  • Blogosphere News
  • email
  • LinkedIn
  • Linkter
  • Live
  • MyShare
  • MySpace
  • Ping.fm
  • StumbleUpon
  • Technorati
  • Yahoo! Bookmarks
  • Yahoo! Buzz

Related posts:

  1. Custom css for article
  2. Custom post types with custom taxonomies
  3. How to create a custom post type in Wordpress 3.0
  4. show last comments with the avatar in wordpress
  5. Wordpress 3.0:Style WordPress editor using CSS

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

SEO Powered by Platinum SEO from Techblissonline