脚本宝典收集整理的这篇文章主要介绍了php – 使用另一个标签为WordPress RSS添加缩略图,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
/* 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>链接< / 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; });
以上是脚本宝典为你收集整理的php – 使用另一个标签为WordPress RSS添加缩略图全部内容,希望文章能够帮你解决php – 使用另一个标签为WordPress RSS添加缩略图所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。