2429 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
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!

2429 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
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
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 100 and 199 users
+2 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
2429 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
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
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 100 and 199 users
+2 more
duotive says

try permalink without echo get_permalink()

2429 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
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
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 100 and 199 users
+2 more
duotive says

you are welcome :)

2429 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
digitalimpact says

Sorry for the late update…

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

122 posts
  • Bought between 50 and 99 items
  • Denmark
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 1 000 and 5 000 dollars
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' );
2429 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
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