We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32678
    • 290 Posts
    Hi there--

    I am trying to determine how to include a thumbnail image in a Wordpress-generated RSS feed in the output of a ModX RSS snippet.

    I currently using getFeed on an Evo site, and am rebuilding this site in Revo, for which the spieFeed snippet includes a range of placeholders not used by getFeed.

    I pulled the tpl param from the getFeed call and got the array values of the WP feed. I found the following (edited for readability by removing URLs, classes, etc.:

    [category] => VALUE
        [guid] => URL
        [description] => POST DESCRIPTION
        [content] => Array
            (
                [encoded] => <p><a class="..." href="POST URL" title="..."><img class="..." src="POST THUMBNAIL" width="..." height="..." alt="IMG ALT TXT" /></a>
    </p>
    <p>THE POST CONTENT</p>...


    spieFeed includes a CONTENT placeholder, which is where the image is placed, but this includes all of the post's content. I assume there's is no way to selectively output the image only, and that the only way to usefully use this placeholder for a feed summary would be to limit the number of characters that are output. Looking through the SimplePie API documentation, I don't see anything there that can accomplish this.

    In any case, any insight from the modx gurus would be greatly appreciated. I am not a programmer, so anything beyond a simple fix is likely beyond my grasp. This is important enough, though, that I would pay someone to modify the snippet. Hence, if there is a solution to this, I'd love to hear about it.

    Thanks,
    Wesley
      • 38723
      • 165 Posts
      Is the feed from Wordpress available as JSON instead?
        • 32678
        • 290 Posts
        Hmmm, great thought! Short answer is no, not natively. There appears to be a couple Wordpress plug-ins that do the conversion, but I found and have implemented an approach that uses a Javascript and the Google Feed API. Here's the post about it: http://www.my-html-codes.com/convert-xml-to-json

        I have it working on my site. I now need to figure out two things.

        First, how to place the image in the array into the output. It's a question of modifying the Javascript, which follows, correctly:

        var getFeed = function(feed) {
        	var url = feed;
        	url += "&callback=parse_res"
        	var scripttag = document.createElement("script");
        	scripttag.setAttribute("type","text/javascript");
        	scripttag.setAttribute("charset","utf-8");
        	scripttag.setAttribute("src",url);
        	document.getElementsByTagName("body")[0].appendChild(scripttag);
        }
        
        var parse_res = function(data) {
        	var entries = data.responseData.feed.entries;
        	var container = document.getElementById("rssFeed");
        	var list = document.createElement("ul");
        	while (container.hasChildNodes()) {
        		container.removeChild(container.lastChild);
        		}
        	 for (var i=0; i<entries.length; i++){
        		 var listItem = document.createElement("li");
        				var title = entries[i].title;	
        				 // create the headline link
        				 var link = document.createElement("a");
        				 link.setAttribute("href", entries[i].link);
        				 link.setAttribute("target","_blank");
        				 var text = document.createTextNode(title);
        				 link.appendChild(text);
        				 // insert the markup
        				 listItem.appendChild(link);
        				 list.appendChild(listItem);
        				 container.appendChild(list);
        			}
        }
        


        Second, this does not output HTML, as in, the post list items do not appear in the page source. This is problematic from an SEO perspective.

        Any thoughts?

        Thanks,
        Wesley
          • 38723
          • 165 Posts
          Is there any chance of looking at the actual XML RSS feed you're starting with? Is it a default Wordpress "news feed" type thing, or one generated by some sort of plugin additional to the base Wordpress install?
          PM the link if you'd like to not make it public just yet!
            • 32678
            • 290 Posts
            Thanks for taking a look.

            The feed is public on my current site. Site address is www.wesleypicotte.com. The blog address, which is the source of the feed, is www.wesleypicotte.com/blog. This site proper is ModX, /blog is a discreet instance of Wordpress.

            The feed is a feedburner feed and its address is http://feeds.feedburner.com/Wesleypicotte.
              • 22840
              • 1,572 Posts
              Were pulling in the featured image on one of our sites ( none modx but should work ) with the following, put a blog.png image in the blog folder for when the featured image isn't set. Also to note this wasn't written by me but should work without anything else.

              Also to note you will have to edit the line that states the category to pull from and the limit query_posts('showposts=2&cat=-112'); if (have_posts()) :

              <?php
                  define('WP_USE_THEMES', false);
                  require('blog/wp-blog-header.php');
              ?>
              
              
              
              <?php 
                  query_posts('showposts=2&cat=-112'); if (have_posts()) : ?>  
                  <?php while (have_posts()) : the_post(); ?>  
                  
                      <?php
                          $count++;
                          $image_thumb = '';
                                                      
                          if(has_post_thumbnail(get_the_ID(), 'blog_ft'))
                          {
                              $image_id = get_post_thumbnail_id(get_the_ID());
                              $image_thumb = wp_get_attachment_image_src($image_id, 'blog_ft', true);
                          }
                      ?>
                      <dt>
                          <?php
                              if(!empty($image_thumb))
                              {
                          ?>
                              <img class="blogimg" src="<?php echo $image_thumb[0]; ?>" alt="" />
                          <?php
                              } else {
                          ?>
                              <img class="blogimg" src="www.wesleypicotte.com/blog/blog.png" alt="" />                 
                          <?php } ?>
                          <br />
                          <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                      </dt>
                      <dd>
                          <?php
                              $content = get_the_content();
                              $content = strip_tags($content);
                              echo substr($content, 0, 100);
                          ?>
                          <br />
                          <br />
                          <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"  style="font-size: 12px;">Read Article </a> 
                      </dd>
                  <?php endwhile; ?>  
              <?php else : ?>  
                  Sorry, no posts were found.
              <?php endif; ?> 
              
              
              <?php endif; wp_reset_query(); ?> 
                • 38723
                • 165 Posts
                Quote from: wpicotte at Oct 15, 2013, 11:26 AM
                Thanks for taking a look.

                The feed is public on my current site. Site address is www.wesleypicotte.com. The blog address, which is the source of the feed, is www.wesleypicotte.com/blog. This site proper is ModX, /blog is a discreet instance of Wordpress.

                The feed is a feedburner feed and its address is http://feeds.feedburner.com/Wesleypicotte.

                I think there's more than one issue here. Also, if you want a Wordpress feed - it's enabled by default here: http://www.wesleypicotte.com/blog/feed
                Both that feed and the feedburner one do not have the image available easily as it's part of the "<content:encoded>" section of an item in both feeds, as you mention in your first post.

                I think you've got two options really:
                1) Have something generate a different feed for you from your blog, but you'd need a way to specify a separate image per post which isn't part of the content. Not sure about Wordpress doing this as I've not used it in quite some time, or...
                2) You're going to need to have a snippet that looks for the content:encoded part of the feed, then finds the img element inside the post_image_link class.