Forums

Pulling First Gallery Image into RSS Feed (5 posts)

  1. isserdude
    Member
    Posted 7 months ago #

    I've been searching and could not get my hands on the correct code or method for doing this:

    I currently upload only 1 image (which I consider a feature image) into my gallery on my post. How do I pull this into my RSS feed?

    I'm sure I need a function and then I need to put it into the RSS feed php, but I'm not sure which one, how to format that or where it needs to go in there.

    I'm usually pretty good at figuring these things out and try to withhold my posting unless its the very last option. This one just has me stumped.

    Thanks for any advice.

  2. Ervald
    Member
    Posted 7 months ago #

    Here's how to get the first attachment.

    // If is not the Featured Thumbnail
    
    $args = array(
        'post_type' => 'attachment',
        'exclude' => get_post_thumbnail_id(the-post-id)
    );
    
    $attachments = get_posts($args);
    if ($attachments) {
        foreach ($attachments as $attachment) {
    
       // echo them here
    
        }
    }
    
    //If is the Featured Thumbnail
    
    $image = wp_get_attachment_image_src( get_post_thumbnail_id(the-post-id), 'single-post-thumbnail' ); 
    
       $imageURL = $image[0];

    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

  3. isserdude
    Member
    Posted 7 months ago #

    Thanks. How would I place that into the RSS feed?

  4. Ervald
    Member
    Posted 7 months ago #

    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');

    To your functions.php

  5. balex
    Member
    Posted 5 months ago #

    Where would you place the first bit of code? I got that the second part goes in the functions.php, but I tried to add the first bit above that second bit in fucntions.php and it threw an error.

    Thanks in advance.

Reply

You must log in to post.

About this Topic