Feedwordpress – Displaying attached images

feedwordpress

Feedwordrpress is a wordpress plugin that syndicates content from RSS feeds to your blog. This is one of the best wordpress plugin if you wish to create an auto blog.

Normally Feedwordpress syndicates images within feeds. But some feeds provide images as attachments of the feed. These images are not shown in the posts created with syndicated posts. But the details of the attachment is saved as a custom field of the post.

Here is a code to display the images attached to the feed. Place this code within The Loop where you want image to be displayed.

<!--?php $enclosure =  get_post_meta($post--->ID , 'enclosure', $single = true); ?>
<!--?php $image=explode(chr(10),$enclosure); ?-->
<!--?php if(!is_null($image)) : ?-->
<img alt="<?php the_title_attribute(); ?>" src="<?php echo $image[0]; ?>" />
<!--?php endif; ?-->

This will display the attached image. You can further customize the display of the image by applying css styles to the image.

note: I have updated the code. If you have used the previous code try using the new code above.

Enjoyed this article? Share with friends

  • Silvio

    Many thanks for your script! Is very usefull :-D

  • Steve Mordue

    Could you be a little more specific about where this code would go?

    • In index.php, single,php, achieve.php files of your theme, there is a code like this;

      < ?php while (have_posts()) : the_post(); ?>



      < ?php endwhile; ?>

      Add the code mentioned in above between these codes.

  • don’t work under A Thematic Child Theme… Help?

  • Mike

    Tried adding this…get “Parse error: syntax error, unexpected ‘”‘ in /home/user/public_html/wp-content/themes/tribune/index.php on line 112″…any thoughts? Thanks!

    • Make sure you have added the code correctly. This worked for many people without any error

  • mark

    hi,

    how would this work for audio enclosues, i am using feedwordpress and need to grab the enclosures from http://tatw.co.uk/podcast.xml, they don’t display in my posts so far and i have tried adding ID, ‘enclosure’); ?> to my post.php template file

    thanks.

    • Above code is only for images. It won’t work with any other files.

      For mp3 files try this code

      <?php $enclosure = get_post_meta($post->ID , ‘enclosure’, $single = true);
      $media=strtok($enclosure,chr(10)); ?>
      <?php if ($media!="") : ?>;
      <?php $url='<a href="'.$media.'" rel="nofollow">'.$media.'</a>';
      echo($url); ?>
      <?php endif; ?>

      update: try this code

      <?php $enclosure = get_post_meta($post->ID , ‘enclosure’, $single = true);
      $media=explode(chr(10),$enclosure); ?>
      <?php if (!is_null($media)) : ?>;
      <?php $url='<a href="'.$media[0].'" rel="nofollow">'.$media[0].'</a>';
      echo($url); ?>
      <?php endif; ?>
      • For the mp3 enclosure…I’d like the text in the link to reflect ideally the title of the post or the name of the mp3. Right now the enclosure is ‘.$media.’ Is there a piece of code I can stick in there so it get’s the title/author of the post. I tried several pieces of WordPress code from the codex but none have worked like . Here’s an example of what I’m trying to do, maybe it will make sense if you see it in full (obviously this doesn’t work though):

        ID , ‘enclosure’, $single = true);
        $media=strtok($enclosure,chr(10)); ?>

        <?php $url=' | ‘;
        echo($url); ?>

        • ID , 'enclosure', $single = true);
          $media=strtok($enclosure,chr(10)); ?>

          <?php $url=' | ';
          echo($url); ?>

        • try this code

          <?php $enclosure = get_post_meta($post->ID , ‘enclosure’, $single = true);
          $media=strtok($enclosure,chr(10)); ?>
          <?php if ($media!="") : ?>
          <?php $url='<a href="'.$media.'" rel="nofollow">'.the_title().'</a>';
          echo($url); ?>
          <?php endif; ?>

          update: try this code

          <?php $enclosure = get_post_meta($post->ID , ‘enclosure’, $single = true);
          $media=explode(chr(10),$enclosure); ?>
          <?php if (!is_null($media)) : ?>;
          <?php $url='<a href="'.$media[0].'" rel="nofollow">'.$media[0].'</a>';
          echo($url); ?>
          <?php endif; ?>
          • Thanks! It strangely half works. It drops in the title which is great…but then the href link ceases to become linkable. An ideas on how to revive the link?

            • check the code again. seems it works.

              • it works in having the title show up but it loses the link to the media and becomes static text. Maybe it’s my theme, may try and switch and see if that will do the trick. My hunch for what I need is that just like you’re using the ‘.$media.’ within the href html I need something formatted like that to grab the title instead. Something like ‘.$title.’ (except that doesn’t work, i’ve tried…i’m not familiar with that convention though…do you know of one I could try?

              • I’ve tried my darndest to get the title code to work. the .title(). definitely doesn’t work on my site…for some reason it loses the link when I put that in. Here’s a page with an example of the enclosure working: http://www.artronica.info/2011/03/27/jason-paul-boy-acapella-improvox-march-25-2011/

                I’d love to have that looong link take on the text of the title so it looks better/more readable. I’ve scoured the web for other solutions but yours is definitely the best…if I could only get that mp3 link to have the title text. I think it’s not quite as simple as dropping in the title, I think I need to define a few more variables…just not sure which ones

                • try assigning the title to a variable & adding it to the code

                  something like this

                  < ?php $mp3title=the_title(); ?>
                  < ?php $url=''.$mp3title.'';
                  echo($url); ?>
                  
                  • no luck. I’d tried some similar stuff. It won’t allow any other text to be hyperlinked except for $media for some reason. I’m guessing I may have to find a way to reorganize this code so it allows other variables inside the hyperlink text.

  • Could someone please do an idiots guide how to do this, I’m not familiar with the loop and editing php files.
    Thanks.

    • This is just a copy & paste work. It won’t be much hard. Anyway if you are not much sure about what you are doing, it’s better you get someone else to do this for you.

  • It definitely works…but I’m having a bit of a problem which may be particular to how I want my site to work. For whatever reason it attaches the link to the mp3 just outside of my Content area instead of firmly inside it. This means that I can’t target the audio with any audio skins or in my case just wanting Yahoo Media Player to see it.

    • try moving the code more top from the current place you have placed it.

      • I’ve found that the Yahoo Media player issue was unrelated to this piece of code. The issue is still seems that I can’t get it to nest squarely inside the post. I’m also using the add-this social plugin and when I insert this code the audio link appears unattractively on top of the addthis share module. It is possible that the problem is actually with the Addthis plugin which opens a different can of worms. May just need to use CSS to shift these things around in a suitable manner.

  • I’m running FeedWordPress, but I am having trouble figuring this out… mainly due to my site configuration I suppose.

    I’m running a StudioPress theme, which actually runs off of 2 different themes at once, so editing files is a pain to begin with.

    I’ve looked in every single file in both themes (most of the files just point to the other theme and vice-versa) and the only one I have in my theme that includes the (have_posts()) is loops.php – which you would assume would make sense

    I’ve added the code there, but no luck… I guess this is a little trickier to implement when you aren’t using a standard WordPress theme.

    Any help would be greatly appreciated.
    You can view my feed here: http://loopana.com/feed/

    I just want to make the attachments show up in the feed, instead of those ugly notepad looking links.

    • Could you give me the link to your wordpress theme. So I can help you if possible.

  • Hello,

    I tried to insert your code but RSS are still without photos.

    Can you help me please?

    • could you please try copying & pasting the code again. Make sure it’s within the loop.

      • Hi again,

        This is the code for index.php, can you tell me where I’m wrong please?

        Thank you very much

        <?php
        if(have_posts()) {

        /* Display navigation to next/previous pages when applicable */
        if ( theme_get_option('theme_' . (theme_is_home() ? 'home_' : '') . 'top_posts_navigation' ) ) {
        theme_page_navigation();
        }

        /* Start the Loop */
        while (have_posts()) {
        the_post();
        get_template_part('content', get_post_format());
        ID , ‘enclosure’, $single = true); ?>

        <img src="” alt=”” />

        }

        /* Display navigation to next/previous pages when applicable */
        if (theme_get_option(‘theme_bottom_posts_navigation’)) {
        theme_page_navigation();
        }

        } else {

        theme_404_content();

        }
        ?>

  • /* Start the Loop */
    while (have_posts()) {
    the_post();
    get_template_part(‘content’, get_post_format());
    ID , ‘enclosure’, $single = true); ?>

    <img src="” alt=”” />

    }

    /* Display navigation to next/previous pages when applicable */
    if (theme_get_option(‘theme_bottom_posts_navigation’)) {
    theme_page_navigation();
    }

    } else {

    theme_404_content();

  • Hi, I’m trying to implement this on a client’s blog page, which is a news syndication using FeedWordPress. Your code should work in theory, and does work for the LAST excerpt on the page (not a single post page, its a series of excerpts one after another). I’m trying to figure out why it’s only working for the last article and not all of them.

    Anyone?

    • I have updated the code. try the new code & check.

  • Hi, I am wanting to use feedworpress to create a post from my libsyn podcast RSS feed, including posting the media into the blubrry powerpress enclosure in my wordpress post.

    Do you know if this is possible?

    Thanks
    Ben.

  • after struggling with this all night i came up with an alternative solution by creating a custom field out of the media enclosure which matches the name of that used by my theme, which works great. your code could come in handy in other situations though, so thanks for looking into that so quickly!

    • great! would you like to share it with other users here?

  • Can someone please tell me where you would paste the mp3 media code? I am having trouble figuring out the correct spot to put it in the loop.php

  • it must be within “< ?php while (have_posts()) : the_post(); ?>” and “< ?php endwhile; ?>“

  • raj

    in which file this code shuold paste

Subscribe

Subscribe to our email feed and never miss a post

Join Us