web-dev-qa-db-fra.com

Comment ajouter une image en rss?

Je souhaite ajouter une image à partir du contenu de l'article dans mon flux RSS, mais tous les tutoriels que je trouve ne concernent que l'image en vedette. Je veux une image du contenu du message et non une image en vedette. Comment puis-je faire ceci?

1
TravelWhere

Voici le lien J'ai trouvé une solution. Comment afficher les miniatures des publications en vedette dans les flux WordPress

collez cet extrait de code dans le fichier functions.php de votre thème

// display featured post thumbnails in WordPress feeds
    function wcs_post_thumbnails_in_feeds( $content ) {
        global $post;
        if( has_post_thumbnail( $post->ID ) ) {

//if you want to show thumbnail image
    $content = '<figure>' . get_the_post_thumbnail( $post->ID, 'thumbnail' ) . '</figure>' . $content;

// if you want to show full image
//$content = '<p>' . get_the_post_thumbnail( $post->ID,'full' ) . '</p>' . $content;

//if you want to custom image using add_image_size()
    //$content = '<figure>' . get_the_post_thumbnail( $post->ID, 'custom-image-size' ) . '</figure>' . $content;
        }
        return $content;
    }
    add_filter( 'the_excerpt_rss', 'wcs_post_thumbnails_in_feeds' );
    add_filter( 'the_content_feed', 'wcs_post_thumbnails_in_feeds' );

Ce sont les concepts comment vous montrer une image de lien externe. Comment vous allez chercher l'image externe, c'est sur vous.

il montre tout le post même image. Il suffit de changer le lien de l'image pour chaque article. ex: src = "'. $ image_url.'"

function rss_feed_from_external_link( $content ) {
    global $post;
    $content = '<figure><img width="150" height="128" src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" class="attachment-thumbnail size-thumbnail wp-post-image" alt="" sizes="100vw" /></figure>' . $content;
    return $content;
}
add_filter( 'the_excerpt_rss', 'rss_feed_from_external_link' );
add_filter( 'the_content_feed', 'rss_feed_from_external_link' );

Image affichée pour un champ personnalisé.

add_filter('the_content', 'custom_fields_for_feeds');
add_filter('the_meta','custom_files_for_feed');

function custom_fields_for_feeds( $content ) {

  global $post;
  global $post;
// Get the custom fields ***

// Checks for thumbnail
  $image = get_post_meta($post->ID, 'Thumbnail', $single = true);
// Checks for thumbnail alt text
  $image_alt = get_post_meta($post->ID, 'Thumbnail Alt', $single = true);
  if($image_alt == '') { $image_alt = 'This image has no alt text'; }

  if($image !== '') {
    $content = '<figure><img src="'.$image.'" alt="'.$image_alt.'" /></figure>' . $content;
    return $content;
  } 
  else {
    $content = $content;
    return $content;
  }

add_filter('the_content', 'custom_fields_for_feeds');
add_filter('the_meta','custom_files_for_feed');

Vous pouvez également utiliser des champs d'image personnalisés à afficher dans le flux RSS.

Faites-moi savoir que vous ne résolvez pas votre problème.

0
Faysal Mahamud