开发者

Link to external URL in post title of RSS feed in WordPress

I have it currently so that my post title links to an external URL using the following code in my index.php file.

<h1><a href="<?php echo get_post_meta($post->ID, 'external-link', true); ?>"><?php the_title(); ?></a> <a h开发者_如何学编程ref="<?php the_permalink() ?>"><small>★</small></a></</h1>

I'd like to have the title of my RSS feed to do the same.

I'm using the FeedBurner FeedSmith plugin (Ver. 2.3.1) if that makes any difference.


Oooo! Unfortunately you have to start editing some of wordpress' files.

In wp_includes there are several files that have a prefix of feed, they are basically just 'feed templates', and in there you'll find the loop. then all you have to do is just replace:

<title><?php the_title_rss() ?></title>

with

<title><?php echo get_post_meta($post->ID, 'external-link', true); ?></title>

for each one, there are some with an ending of -comments, these are for any comments attached to your posts, can choose whether to bother doing these or not, i was extremely lazy and only bothered to edit rss2 hehe.

Anyway, the really annoying bit about this is you wont be able to update your wordpress without these files being overwritten, to overcome that simply duplicate a copy into your theme folder and add this into your functions.php file

//Alter default RSS feed
function disable_our_feeds() {
ob_start();
require_once(ABSPATH. 'wp-content/themes/yourtheme/feed-rss2.php');
$rss2 = ob_get_clean();
die($rss2);
}
add_action('do_feed_rss2', 'disable_our_feeds', 1);

And must add a function for eachand every one of the feeds, annoying eh?

I hope that helps :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜