php - 使用另一个标签将缩略图添加到 WordPress RSS

标签 php wordpress rss feed

我正在使用 Wordpress RSS 在我的 iOS 项目中使用。提要中没有缩略图链接,因此我搜索并找到了这段代码,用于向提要添加缩略图链接。

/* include thumbnail in RSS feed */
function add_thumb_to_RSS($content) {
   global $post;
   if ( has_post_thumbnail( $post->ID ) ){
      $content = '' . get_the_post_thumbnail( $post->ID, 'thumbnail' ) . '' . $content;
   }
   return $content;
}
add_filter('the_excerpt_rss', 'add_thumb_to_RSS');
add_filter('the_content_feed', 'add_thumb_to_RSS')

这段代码在 feed 中添加了图片链接,但它在描述标签的开头添加了 html 代码,如下所示:

<description>
<![CDATA[
<img width="150" height="150" src="http://www.ipadia.co/wp-content/uploads/2012/02/sayfada-bul-150x150.png" class="attachment-thumbnail wp-post-image" alt="sayfada bul" title="sayfada bul" />Some text some text Some text some text Some text some text Some text some text Some text some text Some text some text ....
]]>
</description>

我想用另一个标签添加图像链接,例如 <image><thumb> the link </thumb> .所以我可以更轻松地解析它。

我该怎么做?提前致谢。

最佳答案

我终于解决了:)我更改了我之前发布的功能。新功能是这样的:

add_action('rss2_item', function(){
  global $post;

  $output = '';
  $thumbnail_ID = get_post_thumbnail_id( $post->ID );
  $thumbnail = wp_get_attachment_image_src($thumbnail_ID, 'thumbnail');
  $output .= '<post-thumbnail>';
    $output .= '<url>'. $thumbnail[0] .'</url>';
    $output .= '<width>'. $thumbnail[1] .'</width>';
    $output .= '<height>'. $thumbnail[2] .'</height>';
    $output .= '</post-thumbnail>';

  echo $output;
});

这给出了新标签中的图像链接 <post-thumbnail>就像我想要的那样。

关于php - 使用另一个标签将缩略图添加到 WordPress RSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14257343/

相关文章:

php - 如何获取用户(客户)在 WooCommerce 中花费的总金额?

twitter - 公共(public) Twitter RSS 提要是否有访问限制?

php - 在 Prestashop 的注册表中添加地址字段

php - 在 PHP 中关闭外部连接(例如 memcached、redis)是一个好习惯吗?

html - CSS: Div的位置

Facebook 页面的帖子提要

ios - 如何使用 NotificationCenter UIApplicationDidBecomeActiveNotification 重新加载我的 RSS Feed

php - 如何在php中添加字符串到url?

PHP 错误日志无法正常工作

wordpress - Bitnami的Wordpress Docker设置的持久性