将WordPress特色图像添加到RSS源 [英] Add WordPress featured image to RSS feed

查看:103
本文介绍了将WordPress特色图像添加到RSS源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我的WordPress RSS Feed在MailChimp中设置RSS到电子邮件广告系列,我想在我的MailChimp模板中包含精选图片。
我已经尝试使用它来添加图像,但是它只是将它添加到内容中,这对RSS代码的MailChimp部分不起作用:

I'm setting up an RSS to email campaign in MailChimp using my WordPress RSS Feed, and I want to include the featured image in my MailChimp template. I've tried using this to add the image, which works, but it simply adds it to the content, which doesn't work for MailChimp section of the RSS code:

function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '' . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'float:left; margin:0 15px 15px 0;' ) ) . '' . $content;
}
return $content;
}

add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');

显然,MailChimp希望它是自己的独特图像元素。以下是他们想要的示例: http://kb.mailchimp.com/article/how-can-i-format-the-image-content-in-my-rss-to-email-campaigns

Apparently, MailChimp wants it's "own" unique image element. Here's an example of what they want: http://kb.mailchimp.com/article/how-can-i-format-the-image-content-in-my-rss-to-email-campaigns

但看起来它采用不同的RSS格式。以下是我的RSS输出内容: http://pacmissions.org/dev / mission / zimbabwe-2012 / feed /

but it looks like it's in a different RSS format. Here's what my RSS is outputting: http://pacmissions.org/dev/missions/zimbabwe-2012/feed/

推荐答案

我经常要创建自定义Feed MailChimp,并发现很多时候我必须做一些hacky更改,比如将自定义值放入MailChimp支持的有限标准字段中。

I often have to create custom feeds for MailChimp, and find that a lot of the time I have to make somewhat 'hacky' changes like putting custom values into the limited standard fields that MailChimp supports.

因为这个我喜欢使用Yoast所描述的方法( http://yoast.com/ custom-rss-feeds-wordpress / )创建一个输出自定义RSS提要的页面。

Because of this I like to use the method described at Yoast ( http://yoast.com/custom-rss-feeds-wordpress/ ) to create a page that outputs a custom RSS feed.

有几个调整要做为了将特色图像包含在MailChimp将识别的字段中。

There are couple of tweaks to make in order to get the featured image included as a field that MailChimp will recognise.

首先,您需要添加Media RSS命名空间,我通常通过添加到打开< rss& gt; tag:

Firstly, you need to add the Media RSS namespace, which I usually do by adding to the opening <rss> tag:

<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">

然后为了在项目中包含精选图片:

Then in order to include the featured image inside the item:

<?php if(get_the_post_thumbnail()): ?>
    <media:content url="<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>" medium="image" />
<?php endif; ?>

如果您需要指定要包含的特定图像大小,则需要在内部使用此代码相反的项目:

If you need to specify a particular image size to include, you'll need to use this code inside the item instead:

<?php if(get_the_post_thumbnail()): ?>
    <media:content url="<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'imageSize'); echo $image[0]; ?>" medium="image" />
<?php endif; ?>

然后你可以使用 * | RSSITEM在MailChimp中获取此信息。 * * | FEEDITEM:IMAGE | * 合并标签。

You can then grab this in MailChimp using the *|RSSITEM:IMAGE|* or *|FEEDITEM:IMAGE|* merge tags.

这篇关于将WordPress特色图像添加到RSS源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆