2017-03-02 43 views
1

我有这在我的functions.php工作正常,我只想要特色图像链接到帖子。如何在RSS中包装精选图片的帖子url?

add_filter('the_excerpt_rss', 'featured_image_in_feed'); 
function featured_image_in_feed($content) { 
global $post; 
if(is_feed()) { 
    if (has_post_thumbnail($post->ID)){ 
     $output = get_the_post_thumbnail($post->ID, 'medium', array('style' => 'width:100%; margin-bottom:15px; display: inline-block;')); 
     $content = $output . $content; 
    } 
} 
return $content; 
} 

这是输出

<description><![CDATA[<img width="564" height="153" src="http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484-564x153.jpg" class="attachment-medium size-medium wp-post-image" alt="checklist" style="width:100%; margin-bottom:15px; display: inline-block;" srcset="http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484-564x153.jpg 564w, http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484-768x208.jpg 768w, http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484.jpg 880w" sizes="(max-width: 564px) 100vw, 564px" />Teaser text is here]]></description> 

而且我想它是

<description><![CDATA[<a href="linktothepost"><img width="564" height="153" src="http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484-564x153.jpg" class="attachment-medium size-medium wp-post-image" alt="checklist" style="width:100%; margin-bottom:15px; display: inline-block;" srcset="http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484-564x153.jpg 564w, http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484-768x208.jpg 768w, http://mywebsite.com/blog/wp-content/uploads/2017/03/Checklist-crop-ID-85484.jpg 880w" sizes="(max-width: 564px) 100vw, 564px" /></a>Teaser text is here]]></description> 
+0

相对于?显示当前与期望的输出。 – rbellamy

回答

1

由于get_post_thumnail()刚刚返回包含标签的字符串,你应该能够包裹链接。

if (has_post_thumbnail($post->ID)){ 
    $output = '<a href="' . get_permalink($post->ID) . '">'; 
    $output .= get_the_post_thumbnail($post->ID, 'medium', array('style' => 'width:100%; margin-bottom:15px; display: inline-block;')); 
    $output .= '</a>'; 
    $content = $output . $content; 
} 
相关问题