Results 1 to 8 of 8

Thread: wordpress - add custom field images to rss feed

  1. #1
    Trusted Guru WelshStew's Avatar
    Join Date
    Dec 2008
    Posts
    2,555
    Blog Entries
    3

    Default wordpress - add custom field images to rss feed 26 Feb 2010 @ 12.00

    Hi,

    I am using some custom fields in a wordpress installation for images and I would like these added to my RSS2 feed.

    I have tried things like Justin Tadlocks plugin, but they still don't appear.
    Custom Fields For Feeds: WordPress Plugin

    The second part to my query would be to process this feed and only show the images.

    Any help appreciated.
      Reply With Quote

  2. #2
    Trusted Guru saltedm8's Avatar
    Join Date
    Jun 2011
    Posts
    1,969
    Blog Entries
    3

    Default 26 Feb 2010 @ 12.25

    should be relatively simple as long as the plugin works and is compatible with anything you currently have..

    have you created the custom fields ?.. with the proper values etc, they are case sensitive.

    seems simple, but that's the first thing I would check ( obviously after checking the plugin is activated lol )
      Reply With Quote

  3. #3
    Trusted Guru WelshStew's Avatar
    Join Date
    Dec 2008
    Posts
    2,555
    Blog Entries
    3

    Default 26 Feb 2010 @ 12.30

    yeah, it's all active and the plugin is calling in the same value as the custom field.

    PHP Code:
    <?php
    /*
    Plugin Name: Custom Fields for Feeds
    Plugin URI: http://justintadlock.com/archives/2008/01/27/custom-fields-for-feeds-wordpress-plugin
    Description: This puts images or videos into your feeds through the use of custom fields.  You can alter the custom field Keys and what is displayed.
    Author: Justin Tadlock
    Version: 1.0.1 Beta
    Author URI: http://justintadlock.com
    License: GPL
    */

    /*  Copyright 2007 Justin Tadlock  (email : justin@justintadlock.com)

        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */

    /*
       Modified by Stewart Griffiths of WelshStew to specifically show images.
     */

    add_filter('the_content''custom_fields_for_feeds');

    function 
    custom_fields_for_feeds$content ) {

    global 
    $post$id;
    $blog_key substrmd5get_bloginfo('url') ), 016 );
    if ( ! 
    is_feed() ) return $content;

    // Place your own four custom fields by replacing the capital text
        
    $image get_post_meta($post->ID'thumbnail'$single true);
        

    // If there's an image, display the image with the content
    // Feel free to change the styling of the image border
        
    if($image !== '') {
        
    $content '<p style="float:right; padding:1px; border:1px #dddddd solid; margin-left:15px; width:125px; height:125px;">
        <img src="'
    .$image.'" alt="Logo Inspiration" width="125" height="125" />
        </p>' 
    $content;
        return 
    $content;
        } 
    // End if image

    // If there's not an image, just display the content
        
    else {
        
    $content $content;
        return 
    $content;
        }
    // End function
    ?>
      Reply With Quote

  4. #4
    Trusted Guru saltedm8's Avatar
    Join Date
    Jun 2011
    Posts
    1,969
    Blog Entries
    3

    Default 26 Feb 2010 @ 13.47

    could you post the original so I can compare them ?
      Reply With Quote

  5. #5
    Trusted Guru WelshStew's Avatar
    Join Date
    Dec 2008
    Posts
    2,555
    Blog Entries
    3

    Default 26 Feb 2010 @ 14.30

    here you go:

    PHP Code:
    <?php
    /*
    Plugin Name: Custom Fields for Feeds
    Plugin URI: http://justintadlock.com/archives/2008/01/27/custom-fields-for-feeds-wordpress-plugin
    Description: This puts images or videos into your feeds through the use of custom fields.  You can alter the custom field Keys and what is displayed.
    Author: Justin Tadlock
    Version: 1.0.1 Beta
    Author URI: http://justintadlock.com
    License: GPL
    */

    /*  Copyright 2007 Justin Tadlock  (email : justin@justintadlock.com)

        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */

    add_filter('the_content''custom_fields_for_feeds');

    function 
    custom_fields_for_feeds$content ) {

    global 
    $post$id;
    $blog_key substrmd5get_bloginfo('url') ), 016 );
    if ( ! 
    is_feed() ) return $content;

    // Get the custom fields ***

    // Checks to see if there's an image
        
    $image get_post_meta($post->ID'Image'$single true);
        
    $image_alt get_post_meta($post->ID'Image Alt'$single true);

    // If there's a Feature Full
        
    if($image == '') {
        
    $image get_post_meta($post->ID'Feature Full'$single true);
        
    $image_alt get_post_meta($post->ID'Feature Full Alt'$single true);
        }

    // If there's a Feature Image
        
    if($image == '') {
        
    $image get_post_meta($post->ID'Feature Image'$single true);
        
    $image_alt get_post_meta($post->ID'Feature Image Alt'$single true);
        }

    // If there's a Thumbnail Large
        
    if($image == '') {
        
    $image get_post_meta($post->ID'Thumbnail Large'$single true);
        
    $image_alt get_post_meta($post->ID'Feature Large Alt'$single true);
        }

    // If there's a Thumbnail
        
    if($image == '') {
        
    $image get_post_meta($post->ID'Thumbnail'$single true);
        
    $image_alt get_post_meta($post->ID'Thumbnail Alt'$single true);
        }

    // If there's no "Image Alt," "Feature Image Alt," or "Thumbnail Alt"
        
    if($image_alt == '') { $image_alt 'This image has no alt text'; }

    // Checks to see if there's a video (YouTube, Google Video, etc.) associated with this post
        
    $video get_post_meta($post->ID'Video'$single=true);

    // Displaying the content ***

    // If there's a video, display the video with the content
        
    if($video !== '') {
        
    $content '<p>
        <object type="application/x-shockwave-flash" data="'
    .$video.'" class="left" style="align: left; width: 275px; height: 230px; border: none; padding: 0; margin: 0;" id="video">
            <param name="movie" value="'
    .$video.'" />
            <param name="wmode" value="transparent" />
            <param name="quality" value="best" />
            <param name="bgcolor" value="#ffffff" />
            <param name="FlashVars" value="playerMode=embedded" />
        </object>
        </p>' 
    $content;
        return 
    $content;
        } 
    // End if video

    // If there's not a video but an image, display the image with the content
        
    elseif($image !== '') {
        
    $content '<p>
        <img src="'
    .$image.'" alt="'.$image_alt.'" />
        </p>' 
    $content;
        return 
    $content;
        } 
    // End if image

    // If there's not an image or video, display the content
        
    else {
        
    $content $content;
        return 
    $content;
        }
    // End function
    ?>
      Reply With Quote

  6. #6
    Trusted Guru saltedm8's Avatar
    Join Date
    Jun 2011
    Posts
    1,969
    Blog Entries
    3

    Default 26 Feb 2010 @ 15.03

    not saying it will work as I cant test it, but try this

    PHP Code:
    <?php
    /*
    Plugin Name: Custom Fields for Feeds
    Plugin URI: http://justintadlock.com/archives/2008/01/27/custom-fields-for-feeds-wordpress-plugin
    Description: This puts images or videos into your feeds through the use of custom fields.  You can alter the custom field Keys and what is displayed.
    Author: Justin Tadlock
    Version: 1.0.1 Beta
    Author URI: http://justintadlock.com
    License: GPL
    */

    /*  Copyright 2007 Justin Tadlock  (email : justin@justintadlock.com)

        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */

    /*
       Modified by Stewart Griffiths of WelshStew to specifically show images.
     */

    add_filter('the_content''custom_fields_for_feeds');

    function 
    custom_fields_for_feeds$content ) {

    global 
    $post$id;
    $blog_key substrmd5get_bloginfo('url') ), 016 );
    if ( ! 
    is_feed() ) return $content;

    // Place your own four custom fields by replacing the capital text
        
    if($image == '') {
        
    $image get_post_meta($post->ID'thumbnail'$single true);
        }

    // If there's an image, display the image with the content
    // Feel free to change the styling of the image border
        
    if($image !== '') {
        
    $content '<p style="float:right; padding:1px; border:1px #dddddd solid; margin-left:15px; width:125px; height:125px;">
        <img src="'
    .$image.'" alt="Logo Inspiration" width="125" height="125" />
        </p>' 
    $content;
        return 
    $content;
        } 
    // End if image

    // If there's not an image, just display the content
        
    else {
        
    $content $content;
        return 
    $content;
        }
    // End function
    ?>
    if not, try this one

    PHP Code:
    <?php
    /*
    Plugin Name: Custom Fields for Feeds
    Plugin URI: http://justintadlock.com/archives/2008/01/27/custom-fields-for-feeds-wordpress-plugin
    Description: This puts images or videos into your feeds through the use of custom fields.  You can alter the custom field Keys and what is displayed.
    Author: Justin Tadlock
    Version: 1.0.1 Beta
    Author URI: http://justintadlock.com
    License: GPL
    */

    /*  Copyright 2007 Justin Tadlock  (email : justin@justintadlock.com)

        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */

    /*
       Modified by Stewart Griffiths of WelshStew to specifically show images.
     */

    add_filter('the_content''custom_fields_for_feeds');

    function 
    custom_fields_for_feeds$content ) {

    global 
    $post$id;
    $blog_key substrmd5get_bloginfo('url') ), 016 );
    if ( ! 
    is_feed() ) return $content;

    // Place your own four custom fields by replacing the capital text
        
    if($image == '') {
        
    $image get_post_meta($post->ID'thumbnail'$single true);
        }

    // If there's an image, display the image with the content
    // Feel free to change the styling of the image border
        
    if($image == '') {
        
    $content '<p style="float:right; padding:1px; border:1px #dddddd solid; margin-left:15px; width:125px; height:125px;">
        <img src="'
    .$image.'" alt="Logo Inspiration" width="125" height="125" />
        </p>' 
    $content;
        return 
    $content;
        } 
    // End if image

    // If there's not an image, just display the content
        
    else {
        
    $content $content;
        return 
    $content;
        }
    // End function
    ?>
      Reply With Quote

  7. #7
    Trusted Guru WelshStew's Avatar
    Join Date
    Dec 2008
    Posts
    2,555
    Blog Entries
    3

    Default 26 Feb 2010 @ 15.20

    Can you highlight the changes you have made and explain them a little so that I know what is going on.

    Cheers,
      Reply With Quote

  8. #8
    Trusted Guru saltedm8's Avatar
    Join Date
    Jun 2011
    Posts
    1,969
    Blog Entries
    3

    Default 26 Feb 2010 @ 16.01

    this is the first change

    PHP Code:
    // Place your own four custom fields by replacing the capital text
        
    if($image == '') {
        
    $image get_post_meta($post->ID'thumbnail'$single true);
        } 
    I am only testing, but it looks like there is a possibility you remove a condition that you may have needed

    and this is the second
    PHP Code:
     // If there's an image, display the image with the content
    // Feel free to change the styling of the image border
        
    if($image == '') { 
    on this one, I removed the ! just in case it was not an 'if not' .
      Reply With Quote

Similar Threads

  1. SQL joining more than one field in the same table
    By stu2000 in forum General Design & Development Issues
    Replies: 5
    Last Post: 28 May 2010, @ 15.08
  2. Embedding Blog Feed
    By fbmagik in forum Just Starting Out - Help Me!
    Replies: 7
    Last Post: 13 Apr 2010, @ 19.51
  3. Custom wordpress theme integration
    By Jacob in forum Free Reviews & Showcase
    Replies: 4
    Last Post: 28 Jul 2009, @ 22.42

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •