Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Include Image From Inside Single Post Template In RSS Feed? WordPress

  • SOLVED

Hi Guys,

On specific custom post pages there is a div that loads a custom image.

This div is identified as: <strong><div id="main-pic"></strong>

When you pull up the RSS feed for the author it doesn't display images from these custom post type posts.

I was wondering if you can include any images used in <strong><div id="main-pic"></div></strong> for single posts by an author in the author's RSS feed?



And make sure that it has a specific size as well? - So it should be resized to specific dimensions.

Here is the code that is in the source code of the custom post type template:

<?php if(get_option('cp_ad_images') == 'yes'): ?>

<div class="bigleft">


<div id="main-pic">

<?php cp_get_image_url(); ?>

<div class="clr"></div>
</div>

<div id="thumbs-pic">

<?php if(get_post_meta($post->ID, 'images', true)) echo cp_get_image_thumbs_legacy($post->ID, get_option('thumbnail_size_w'), get_option('thumbnail_size_h'), $post->post_title); else cp_get_image_url_single($post->ID, 'thumbnail', $post->post_title, -1); ?>

<div class="clr"></div>
</div>

</div><!-- /bigleft -->


This code is position inside the loop as well.

Suggestions and ideas are very much appreciated.

I've also pasted the complete template code here:


[[LINK href="http://pastie.org/1582666"]]http://pastie.org/1582666[[/LINK]]

Answers (1)

2011-02-19

John Cotton answers:

Hi Edwin

Your question isn't entirely clear to me, sorry.

Are you saying that when you view the RSS feed for the site, you get the page content for the custom type but not any images?

If so, that makes sense since the RSS feed knows nothing about anything external to the post content or excerpt.

The solution depends on exactly what you want to achieve, but if adding an image element to the description is what you want, then something like this:



add_filter('the_excerpt_rss','insert_custom_image');
function insert_custom_image($output) {
// I'm assuming that this function gives you back all you need
$image = cp_get_image_url();
// Do more manipulation if not, eg sizing...

// Very simplistic - you could preg_replace if you want it somewhere else
$output = $image . $output

return $output;
}


Regards

John


Edwin comments:

Hi John,

<blockquote>Your question isn't entirely clear to me, sorry.</blockquote>

That's okay, you pretty much described what I want.

I've tried you code snippet, but I get this error:

Parse error: syntax error, unexpected T_RETURN in /myfilepath... on line 137

Line 137 is this part: return $output;

Have you perhaps forgot to close or add something?


John Cotton comments:

Sorry, there's a missing semi colon.

It should read

add_filter('the_excerpt_rss','insert_custom_image');

function insert_custom_image($output) {

// I'm assuming that this function gives you back all you need

$image = cp_get_image_url();

// Do more manipulation if not, eg sizing...



// Very simplistic - you could preg_replace if you want it somewhere else
$output = $image . $output;

return $output;

}


Note the semi colon after $image . $output


Edwin comments:

Ah great! - That worked.

Thank you very much John!
Should you have any more info how to resize the image I would really appreciate it.

Either way I'll select your answer as the winning answer as this was the main obstacle.