ThemeForest

WP attachment images in feed with links

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

2 years ago
1842 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 100 and 199 users
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 :)

2 years ago
2698 posts
  • Has been a member for 1-2 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Forum Superstar
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 1 and 9 items
  • Europe
  • Referred between 50 and 99 users
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
2 years ago
1842 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 100 and 199 users
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…

2 years ago
2698 posts
  • Has been a member for 1-2 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Forum Superstar
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 1 and 9 items
  • Europe
  • Referred between 50 and 99 users
duotive says

try permalink without echo get_permalink()

2 years ago
1842 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 100 and 199 users
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 :)

2 years ago
2698 posts
  • Has been a member for 1-2 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Forum Superstar
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 1 and 9 items
  • Europe
  • Referred between 50 and 99 users
duotive says

you are welcome :)

2 years ago
1842 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 100 and 199 users
digitalimpact says

Sorry for the late update…

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

2 years ago
108 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 50 and 99 items
  • Denmark
  • Referred between 10 and 49 users
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' );
2 years ago
1842 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 100 and 199 users
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 ;)

2 years ago
by
by
by
by
by