【发布时间】:2016-03-17 20:36:58
【问题描述】:
我想要wordpress post rss列表特色图片链接
例如:
<title>Test title</title>
<desc>Test desc</desc>
<image>imagelink</image>
我没有使用插件。
谢谢
【问题讨论】:
我想要wordpress post rss列表特色图片链接
例如:
<title>Test title</title>
<desc>Test desc</desc>
<image>imagelink</image>
我没有使用插件。
谢谢
【问题讨论】:
这样就可以了。将其添加到functions.php 文件中:
// add the namespace to the RSS opening element
add_action( 'rss2_ns', 'custom_prefix_add_media_namespace' );
function custom_prefix_add_media_namespace() {
echo "xmlns:media="http://search.yahoo.com/mrss/"n";
}
// add the requisite tag where a thumbnail exists
add_action( 'rss2_item', 'custom_prefix_add_media_thumbnail' );
function custom_prefix_add_media_thumbnail() {
global $post;
if( has_post_thumbnail( $post->ID )) {
$thumb_ID = get_post_thumbnail_id( $post->ID );
$details = wp_get_attachment_image_src($thumb_ID, 'thumbnail');
if( is_array($details) ) {
echo '<media:thumbnail url="' . $details[0] . '" width="' . $details[1] . '" height="' . $details[2] . '" />';
}
}
}
此外,当您添加此内容时,请务必通过转到“设置”>“永久链接”来重置永久链接(刷新它们),然后将永久链接更改为默认值,然后返回到您定义的设置,或者只是重新保存。
然后,检查您的提要,媒体应该在那里。
【讨论】: