郁金香媒体

创业想法

WordPress 提示:将图像放入 RSS 源中

这是一个非常简单的代码,它允许您在 RSS feed 中插入特色图像,这样,当您在 Facebook 等社交网络上转发您的 feed 时,该图像可以伴随您的帖子的标题和演示。

为此,请转到您的文件 函数.php 添加这些代码行:

  • 如果您只想使用允许您展示图像的本机 WordPress 功能,这里是您需要的代码:

函数 imageRSS($content) {
全球$post;
if (has_post_thumbnail($post->ID)){
$内容 = » . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'float: right; margin:0 0 10px 10px;' ) ) . » 。 $含量;
}
返回$内容;
}

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

  • 如果除了 WordPress 特色图片的原生功能之外,您的某些文章没有特色图片,则 插入 获取图像 将扫描您的文章以查找任何图像以用作特色图像。然后我建议这个代码,如果没有特色图像,将使插件工作 获取图像 查找可能插入到您的文章中的一个:

函数 imageRSS($content) {
全球$post;
if (has_post_thumbnail($post->ID)){
$内容 = » . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'float: right; margin:0 0 10px 10px;' ) ) . » 。 $含量;
}
别的 {
$内容 = » . get_the_image(array('width' => 150, 'image_scan' => true , 'image_class' => », 'meta_key' => array( 'Thumbnail', 'thumbnail' ))) 。 » 。 $含量;
}
返回$内容;
}

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

  • 最后,如果您想检查文章中是否附有图像,以防没有特色图像,您可以使用此代码:

函数 show_image_feed($content) {

全球$post;
$args = 数组(
'post_type' => '附件',
'numberposts' => 1,
'post_status' => 空,
'post_parent' => $post->ID
);

$attachment = get_posts($args);

如果(1TP4附件){

$内容='

'。 $内容。 '
ID)。' >>>阅读更多'; } 返回$内容; add_filter('the_excerpt_rss', 'show_image_feed');

 

我最新的推文

Nouveau short sur Blooness 👉 Relancer la libido, en vrac -> Soleil, vitamine D, diète céto-méditerranéenne, protéines, livres, badinage, marche, HIIT, et pas de régime hypocalorique.
https://buff.ly/445PWvc

Nouveau short sur Blooness 👉 Améliorer son sommeil -> s’exposer à la lumière le matin, limiter les lunettes de soleil, mouiller la chemise au sport, boire du déca, manger maximum 3h avant de dormir, faire une marche digestive et prendre de la mélaton
https://buff.ly/440weAJ

装载更多

不要错过通过电子邮件发送的商业建议

没有垃圾邮件,只有新内容发布时的电子邮件.

4 回复

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

zh_CNZH