2445 posts
  • Has referred 100+ members
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
digitalimpact says

Hey guys, can anyone help me out with this?

I have one attachment image/post and I need to show it as a link to the actual post in the WordPress RSS feed.

I followed a tut and am currently doing this:


<?php function mf_feedimgs($content) {
    global $post, $wpdb; 
    $attachment_id = $wpdb?>get_var("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post->ID' 
AND post_status = 'inherit' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1");

        $content =  '<a href=". the_permalink($post->ID) ."><img src=". wp_get_attachment_url($attachment_id) ." /></a>' . $content;

    return $content;

}
add_filter('the_content_feed', 'mf_feedimgs');
?>

This does output the image in the feed, but instead of linking it to the actual post, it links it to the site homepage and it also echoes the post URL above it, like in the image:

Attachment image output in RSS

I’ve asked on the tutorial site but didn’t get a solution… any ideas?

Thanks!

2445 posts
  • Has referred 100+ members
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
digitalimpact says

Sorry for the shameless bump, but I’m surprised no one answered this…

And since the forum messes up the code, here it is, exactly as used: http://tinypaste.com/8725c.

Appreciate any ideas you guys might have, thanks :)

3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says
to use

wp_get_attachment_url($attachment_id)

you will need to interpret the query with the wordpress function

<?php setup_postdata($post); ?>

this will work :P
2445 posts
  • Has referred 100+ members
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
digitalimpact says

It’s not about the image not showing up.

I use that function both in the feed and on the site and it’s working fine in the later case.

I’m worried about the anchor; if I remove it, it’s all good, image shows up with no link. If I add it, it spits it like in the image above…

3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says

try permalink without echo get_permalink()

2445 posts
  • Has referred 100+ members
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
digitalimpact says

How could I forget that? :P

Thanks, I’ve added it now, but I’ll have to wait for Feedburner to update, so no feedback too soon. :(

Thanks again :)

3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says

you are welcome :)

2445 posts
  • Has referred 100+ members
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
digitalimpact says

Sorry for the late update…

So I can confirm it’s working now, here’s the final code. :)

122 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 50+ items on Envato Market
+2 more
jayjdk says

What about this?

function wptuts_feedimgs( $content ) {
    global $post;

    if ( has_post_thumbnail( $post->ID ) ) 
        $content = '<p><a href=" . get_permalink( $post->ID ) . ">' . get_the_post_thumbnail($post->ID) . '</a></p>' . $content;

    return $content;
}

add_filter( 'the_excerpt_rss', 'wptuts_feedimgs' );
add_filter( 'the_content_feed', 'wptuts_feedimgs' );
2445 posts
  • Has referred 100+ members
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
digitalimpact says

Nope, that also outputs the URL in plaintext above the thumbnail and links the thumbnail to the front page of your site, just as shown in the image I posted above… Try it, you’ll see what I mean…

The code I linked to previously works exactly as intended ;)

by
by
by
by
by
by