Comment ajouter une image à Wordpress RSS-Feed sans plug-in?
-
-
Jepense que vous ajoutez uneimageen vedette dans le contenu,pas sur lesflux.Vérifiez la réponse quej'aipubliée.I think you are adding featured image in content, not on feeds. Check the answer I posted.
-
0
2014-08-28
-
Robert hue
-
-
5 réponses
- votes
-
-
2014-08-28
Voici un exemple .Comment afficher lesminiatures d'articlesen vedette dans lesflux WordPress
collez cetextrait de code dans votrefichierfunctions.php dethème
// display featured post thumbnails in WordPress feeds function wcs_post_thumbnails_in_feeds( $content ) { global $post; if( has_post_thumbnail( $post->ID ) ) { $content = '<p>' . get_the_post_thumbnail( $post->ID ) . '</p>' . $content; } return $content; } add_filter( 'the_excerpt_rss', 'wcs_post_thumbnails_in_feeds' ); add_filter( 'the_content_feed', 'wcs_post_thumbnails_in_feeds' );
Here is a great example. How to display featured post thumbnails in WordPress feeds
paste this code snippet in your theme functions.php file
// display featured post thumbnails in WordPress feeds function wcs_post_thumbnails_in_feeds( $content ) { global $post; if( has_post_thumbnail( $post->ID ) ) { $content = '<p>' . get_the_post_thumbnail( $post->ID ) . '</p>' . $content; } return $content; } add_filter( 'the_excerpt_rss', 'wcs_post_thumbnails_in_feeds' ); add_filter( 'the_content_feed', 'wcs_post_thumbnails_in_feeds' );
-
Commentpuis-je ajouter une URL d'imageet untitreimg entant que clés séparées dans XML?How can I add imgURL and imgTitle as seperate keys in XML?
-
0
2014-08-28
-
zkanoca
-
-
Pour cela,vous devrezmodifier lemodèle deflux.Voici untutorielpour cela.http://digwp.com/2012/10/customizing-wordpress-feeds/#customize-templatesFor that you will have to modify Feed template. Here is a tutorial for that. http://digwp.com/2012/10/customizing-wordpress-feeds/#customize-templates
-
0
2014-08-28
-
Robert hue
-
-
Jeferaismieux demanipuler la chaîne de description.(:I'd better manipulate description string. (:
-
0
2014-08-28
-
zkanoca
-
-
Que veux-tufaireexactement?Si vouspouvezexpliquerplus,peut-être que quelqu'unicipeut vous aider.What exactly do you want to do? If you can explain more, may be someone here can help you.
-
0
2014-08-28
-
Robert hue
-
-
Je souhaite afficher lesimageset lestitres des actualitésen vedette sur le composant carrousel d'un Bootstrap.Essayer d'écrire un .php.Et votre aideest assezbonnepour résoudremonproblème.Merci.Je vaisextraire le chemin de l'image de la clé de description.I want to show featured news's images and titles on a Bootstrap's carousel component. Trying to write a .php. And your help is good enough to solve my problem. Thanks. I will extract image path from description key.
-
0
2014-08-28
-
zkanoca
-
-
C'est super.Je suis content d'avoirpu aider.:)That's cool. I am glad I could help. :)
-
0
2014-08-28
-
Robert hue
-
-
@Roberthue Pouvez-vous confirmer que celafonctionnepour les articlesparflux de catégorie?/? cat=15 &feed=rss2@Roberthue Can you confirm that this works for the posts by category feed? /?cat=15&feed=rss2
-
0
2016-04-01
-
jackncoke
-
-
@jackncoke Yeh çamarche.Pourquoipas?Aucunparamètren'est utilisépour le limiterpour la catégorie.@jackncoke Yeh it works. Why wouldn't? There is no parameter used to limit it for category.
-
0
2016-04-18
-
Robert hue
-
-
-
-
2018-01-31
Sur labase desnotesiciet denombreuses autres ressources quej'ai lues,j'aitrouvé cette solution spécifiquementpourtravailler avec le convertisseur RSS vers Email de Mailchimp avec leflux de Wordpress. Leursmodèles utilisent l'extension
<media:content>
de l'élémentitem
pour remplir leurmacro d'image. Ce code va dans lefunctions.php duthème.// Add namespace for media:image element used below add_filter( 'rss2_ns', function(){ echo 'xmlns:media="http://search.yahoo.com/mrss/"'; }); // insert the image object into the RSS item (see MB-191) add_action('rss2_item', function(){ global $post; if (has_post_thumbnail($post->ID)){ $thumbnail_ID = get_post_thumbnail_id($post->ID); $thumbnail = wp_get_attachment_image_src($thumbnail_ID, 'medium'); if (is_array($thumbnail)) { echo '<media:content medium="image" url="' . $thumbnail[0] . '" width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" />'; } } });
Le choix de lataille d'image "moyenne"peut également être "miniature" si vousen voulez unepluspetite.
Based on the notes here and many other resources I read, I came up with this solution specifically to work with Mailchimp RSS to Email converter with the feed from Wordpress. Their templates use the
<media:content>
extension to theitem
element to populate their image macro. This code goes in the functions.php of the theme.// Add namespace for media:image element used below add_filter( 'rss2_ns', function(){ echo 'xmlns:media="http://search.yahoo.com/mrss/"'; }); // insert the image object into the RSS item (see MB-191) add_action('rss2_item', function(){ global $post; if (has_post_thumbnail($post->ID)){ $thumbnail_ID = get_post_thumbnail_id($post->ID); $thumbnail = wp_get_attachment_image_src($thumbnail_ID, 'medium'); if (is_array($thumbnail)) { echo '<media:content medium="image" url="' . $thumbnail[0] . '" width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" />'; } } });
The choice of image size 'medium' can also be 'thumbnail' if you want one smaller.
-
Merci.Juste ce dontj'avaisbesoinpourfaire d'autres agrégateurspourtrouver réellement uneimage.Ilne suffitpas d'ajouter unebalise d'image au contenuThanks. Just what I needed to make other aggregators to actually find an image. Just adding an image tag to the content is not enough
-
5
2018-06-07
-
Juergen
-
-
-
-
2015-12-29
J'aiessayé la réponse sélectionnéeet j'ai obtenu unetrèsgrandeimage dansmonflux.Je recommanderais d'ajouter unetaille d'image au code.
// display featured post thumbnails in RSS feeds function WPGood_rss_thumbs( $content ) { global $post; if( has_post_thumbnail( $post->ID ) ) { $content = '<figure>' . get_the_post_thumbnail( $post->ID, 'thumbnail' ) . '</figure>' . $content; } return $content; } add_filter( 'the_excerpt_rss', 'WPGood_rss_thumbs' ); add_filter( 'the_content_feed', 'WPGood_rss_thumbs' );
J'ai utilisé "miniature"pourmonflux,mais "moyen"pourraitmieuxfonctionner sur certains sites.
I tried the selected answer and got a really big image in my feed. I would recommend adding an image size to the code.
// display featured post thumbnails in RSS feeds function WPGood_rss_thumbs( $content ) { global $post; if( has_post_thumbnail( $post->ID ) ) { $content = '<figure>' . get_the_post_thumbnail( $post->ID, 'thumbnail' ) . '</figure>' . $content; } return $content; } add_filter( 'the_excerpt_rss', 'WPGood_rss_thumbs' ); add_filter( 'the_content_feed', 'WPGood_rss_thumbs' );
I used 'thumbnail' for my feed, but 'medium' might work better for some sites.
-
-
-
2020-05-11
Voici comment récupérer lesimages avec le lienet letitre de l'article,àpartir d'unflux rssexterne.
<div class="row"> <?php /* * Get latest blog entries from RSS feed blog * Sort the entries by published date * Get Featured Image SRC and ALT attributes using Regexp * Loop and repeat it 4 times, to display 4 articles */ $feed = 'https://www.somewpsite.com/feed/'; $entries = array(); $xml = simplexml_load_file($feed); $entries = array_merge($entries, $xml->xpath("//item")); //Sort feed entries by pubDate usort($entries, function ($feed1, $feed2) { return strtotime($feed2->pubDate) - strtotime($feed1->pubDate); }); ?> <?php $counter = 0; foreach ($entries as $entry) { //get Featured Image //Enter entry blog Content $blogContent = $entry->description; //regexp to find img attribute preg_match('/(<img[^>]+>)/i', $blogContent, $matches); //store the first img to var $featuredImage = $matches[0]; //Get src attr with regexp preg_match('@src="([^"]+)"@', $featuredImage, $getSrc); //Get alt attr with regexp preg_match('@alt="([^"]+)"@', $featuredImage, $getAlt); //Store the filtered Attributes to display them. $imgAlt = array_pop($getAlt); $imgSrc = array_pop($getSrc); // remove url parameters $url = $entry->link; $url = strtok($url, '?'); //Set counter to iterate over 4 items and then stop the loop. if ($counter <= 3) { ?> <div class="col-12 col-sm-12 col-md-6 col-lg-3 col-xl-3"> <div class="imgContainer"> <a href="<?php echo $url ?>"> <img src="<?php echo $imgSrc ?>" alt="<?php echo $imgAlt; ?>" class="img-fluid"> </a> </div> <h4> <a class="blog-entry-link" href="<?php echo $url ?>"><?= $entry->title ?></a> </h4> </div> <?php $counter++; } // end counter condition }// end for loop ?> </div>
Here is how I fetch the images along with the link and post title, from external rss feed.
<div class="row"> <?php /* * Get latest blog entries from RSS feed blog * Sort the entries by published date * Get Featured Image SRC and ALT attributes using Regexp * Loop and repeat it 4 times, to display 4 articles */ $feed = 'https://www.somewpsite.com/feed/'; $entries = array(); $xml = simplexml_load_file($feed); $entries = array_merge($entries, $xml->xpath("//item")); //Sort feed entries by pubDate usort($entries, function ($feed1, $feed2) { return strtotime($feed2->pubDate) - strtotime($feed1->pubDate); }); ?> <?php $counter = 0; foreach ($entries as $entry) { //get Featured Image //Enter entry blog Content $blogContent = $entry->description; //regexp to find img attribute preg_match('/(<img[^>]+>)/i', $blogContent, $matches); //store the first img to var $featuredImage = $matches[0]; //Get src attr with regexp preg_match('@src="([^"]+)"@', $featuredImage, $getSrc); //Get alt attr with regexp preg_match('@alt="([^"]+)"@', $featuredImage, $getAlt); //Store the filtered Attributes to display them. $imgAlt = array_pop($getAlt); $imgSrc = array_pop($getSrc); // remove url parameters $url = $entry->link; $url = strtok($url, '?'); //Set counter to iterate over 4 items and then stop the loop. if ($counter <= 3) { ?> <div class="col-12 col-sm-12 col-md-6 col-lg-3 col-xl-3"> <div class="imgContainer"> <a href="<?php echo $url ?>"> <img src="<?php echo $imgSrc ?>" alt="<?php echo $imgAlt; ?>" class="img-fluid"> </a> </div> <h4> <a class="blog-entry-link" href="<?php echo $url ?>"><?= $entry->title ?></a> </h4> </div> <?php $counter++; } // end counter condition }// end for loop ?> </div>
-
-
-
2017-10-19
J'aiessayé ces réponses ci-dessuset jen'aipas réussi à lesfairefonctionner.Il a continué à ajoutermonimage dans la zone de description.
J'aitrouvé ceci sur un autre siteet l'aimodifié unpeuet voilà,ça a commencé àfonctionner.
add_action('rss2_item', function(){ global $post; if(has_post_thumbnail($post->ID)){ $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; } });
I tried these answers above and was not able to get it to work. It kept adding my image in the description area.
I found this on another site and modified it a bit and voila it started working.
add_action('rss2_item', function(){ global $post; if(has_post_thumbnail($post->ID)){ $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; } });
-
J'ai recherché l'ajout d'uneimagemettanten vedette auflux RSS sansplug-inpour WordPress. J'aitrouvé quelquesexempleset appliqué lamanière dontil a étéenseigné. Maistout ce quej'aimaintenantn'est rien. Impossible d'atteindre l'image.
La dernièreet lameilleure solution (selonmoi) (commeindiqué ici ) J'aitrouvé quej'ajoute le code suivant aux
duthème actuelfunctions.php
Jen'ai vu aucun changement. Y a-t-il autre chose àfaire?
Ce queje veuxfaire,c'est ajouter uneimage avec une autre clé dans le XML. Ce seraitplusfacile de l'afficherpourmon curseur.