• Resolved arquiNETWORK

    (@arquinetwork)


    hi.

    im building an ios app for my blog which basically is created with rss feeds. i need an xml/feed for every image gallery attached to a post and i think the easiest way to do it and to associate the gallery to a post is modifying the template used for the comments (feeds-rss2-comments.php) so far i have manage to retrieve the images from the gallery using the following code:

    <?php
        $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'order'=>'ASC', 'post_mime_type' =>'image') );
        foreach ( $attachments as $attachment_id => $attachment ) {
                echo wp_get_attachment_image( $attachment_id, 'medium' );
        }
    ?>

    and i placed it in feeds-rss2-comments.php as follows

    <?php
    /**
     * RSS2 Feed Template for displaying RSS2 Comments feed.
     *
     * @package WordPress
     */
    
    header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
    $more = 1;
    
    echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
    
    <rss version="2.0"
    	xmlns:content="http://purl.org/rss/1.0/modules/content/"
    	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    	xmlns:dc="http://purl.org/dc/elements/1.1/"
    	xmlns:atom="http://www.w3.org/2005/Atom"
    	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    	<?php do_action('rss2_ns'); do_action('rss2_comments_ns'); ?>
    >
    
    <channel>
    	<title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
    	<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
    	<link><?php (is_single()) ? the_permalink_rss() : bloginfo_rss("url") ?></link>
    	<lastBuildDate><?php echo mysql2date('r', get_lastcommentmodified('GMT')); ?></lastBuildDate>
    	<?php do_action('commentsrss2_head'); ?>
    	<?php while( have_posts()) : the_post(); ?>
    	<item>
    		<title><?php the_title_rss() ?></title>
        <content:encoded><![CDATA[<?php
        $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'order'=>'ASC', 'post_mime_type' =>'image') );
        foreach ( $attachments as $attachment_id => $attachment ) {
                echo wp_get_attachment_image( $attachment_id, 'medium' );
        }
    ?>]]></content:encoded>
        <?php rss_enclosure(); ?>
    	<?php do_action('rss2_item'); ?>
    	</item>
      <?php endwhile; ?>
    </channel>
    </rss>

    that gives the following output

    <rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:georss="http://www.georss.org/georss" version="2.0">
    <channel>
    <title>
    arquitour » Casa de la Cultura de Castro – a.f. abeijón-fernandez arquitectos
    </title>
    <atom:link href="http://www.arquitour.com/casa-de-la-cultura-a-f-abeijon-fernandez-arquitectos/2010/07/feed/" rel="self" type="application/rss+xml"/>
    <link>
    http://www.arquitour.com/casa-de-la-cultura-a-f-abeijon-fernandez-arquitectos/2010/07/
    </link>
    <lastBuildDate>Wed, 12 Dec 2012 00:17:20 +0000</lastBuildDate>
    <generator>http://wordpress.org/?v=3.4.2</generator>
    <item>
    <title>
    Casa de la Cultura de Castro – a.f. abeijón-fernandez arquitectos
    </title>
    <content:encoded>
    <![CDATA[
    <img width="585" height="390" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-P-585x390.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="468" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-18-585x468.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="468" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-17-585x468.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="731" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-16-585x731.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="731" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-15-585x731.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="731" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-14-585x731.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="731" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-13-585x731.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="390" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-12-585x390.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="877" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-11-585x877.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="877" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-10-585x877.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="390" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-9-585x390.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="877" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-8-585x877.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="390" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-7-585x390.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="390" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-6-585x390.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="390" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-5-585x390.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="390" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-4-585x390.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="390" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-3-585x390.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" /><img width="585" height="390" src="http://cdn.arquitour.com/wp-content/uploads/2010/07/CasaCultura-2-585x390.jpg?84cd58" class="attachment-medium" alt="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" title="Casa de la Cultura - a.f. abeijón-fernandez arquitectos" />
    ]]>
    </content:encoded>
    <georss:point>43.1466331 -7.4912901</georss:point>
    </item>
    </channel>
    </rss>
    <!--
     Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/
    
    Page Caching using disk: enhanced
    Database Caching using disk: basic
    Object Caching 1486/1564 objects using disk: basic
    Content Delivery Network via cdn.arquitour.com
    
    Served from: www.arquitour.com @ 2012-12-11 22:04:44
    -->

    and as you can see all images are nested in <content:enconded> and i need an item for each image something like

    <item>
    <content:encoded>image one</content:encoded>
    </item>
    <item>
    <content:encoded>image two</content:encoded>
    </item>

    i have tried all possible ways to achieve this but im no able to do it, does any body knows how to do this?

    i would really really really apreciate your help.

    thanks
    /cas

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You just need to correctly rearrange things. In your feed php file, replace the entire <content:encoded> block, including the opening and closing tags, with:

    <?php
        $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'order'=>'ASC', 'post_mime_type' =>'image') );
        foreach ( $attachments as $attachment_id => $attachment ) {
        	    echo '<item><content:encoded>';
                echo wp_get_attachment_image( $attachment_id, 'medium' );
                echo '</content:encoded></item>';
        }
    ?>

    Thread Starter arquiNETWORK

    (@arquinetwork)

    bcworkz

    thank you sir, that worked like a charm i just modified to include the post title

    <?php
        $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'order'=>'ASC', 'post_mime_type' =>'image') );
        foreach ( $attachments as $attachment_id => $attachment ) {
        	    echo '<item><content:encoded>';
                echo wp_get_attachment_image( $attachment_id, 'medium' );
                echo '</content:encoded>';
                echo '<title>';
                echo the_title_rss();
                echo '</title></item>';
        }
    ?

    once again, thank you very very very much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘create a new xml/rss just for the image gallery (help/how to?)’ is closed to new replies.