ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Add Twitter to Existing site RSS Feed?

June 06, 2009 9:46am

Subscribe [4]
  • #1 / Jun 06, 2009 9:46am

    medic119

    52 posts

    I need to preface this by saying I know almost nothing about formatting RSS Feeds properly.  I tried Google and such to try to figure out how to add my Twitter RSS feed to my Site RSS (conglomerate feeds) without luck, so I am asking the gurus here.

    My latest Tweet is listed above my articles on the index of my site.  I did this since most times I send out a short Tweet when I don’t have enough material for a full article.  I use the Twitter timeline plugin.

    What I want to do is add my tweet to my sites standard RSS 2.0 feed.  I realize that my readers could just add the Twitter RSS to their RSS lists, but this way it shows up inside the feeds related to my site and is more convenient for the user.

    I could probably hack it into the template above the exp:weblog:entries tag, but not really know much about RSS XML formatting I would probably end up futzing the entire feed somehow.
    Any would be appreciated as I am operating blindly when it comes to this. Current RSS Feed template below.

    Thanks.

    {assign_variable:master_weblog_name="ffp"}
    {assign_variable:my_template_group="scrapbook"}
    {exp:rss:feed weblog="{master_weblog_name}"}
    
    <?xml version="1.0" encoding="{encoding}"?>
    <rss version="2.0"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
        xmlns:admin="http://webns.net/mvcb/"
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:content="http://purl.org/rss/1.0/modules/content/">
    
        <channel>
        
        <title>{exp:xml_encode}{weblog_name}{/exp:xml_encode}</title>
        <link>{weblog_url}</link>
        <description>{weblog_description}</description>
        <dc:language>{weblog_language}</dc:language>
        <dc:creator>{email}</dc:creator>
        <dc:rights>Copyright {gmt_date format="%Y"}</dc:rights>
        <dc:date>{gmt_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
        <admin:generatorAgent rdf:resource="http://www.pmachine.com/" >
        
    {exp:weblog:entries weblog="{master_weblog_name}" limit="10" rdf="off" dynamic_start="on" disable="member_data|trackbacks"}
        <item>
          <title>{exp:xml_encode}{title}{/exp:xml_encode}</title>
          <link>{title_permalink={my_template_group}/individual}</link>
          <guid>{title_permalink={my_template_group}/individual}#When:{gmt_entry_date format="%H:%i:%sZ"}</guid>
          <description>{exp:xml_encode}{summary}{body}{/exp:xml_encode}</description>
          <dc:subject>{exp:xml_encode}{categories backspace="1"}{category_name}, {/categories}{/exp:xml_encode}</dc:subject>
          <dc:date>{gmt_entry_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
        </item>
    {/exp:weblog:entries}
        
        </channel>
    </rss>
    
    {/exp:rss:feed}
  • #2 / Jun 06, 2009 7:10pm

    bo-oz

    126 posts

    You can use the same plugin that displays your latest tweet inside your RSS template to display it. Could you show how you use this plugin on your frontpage? Then it will be a piece of cake to include it in the feed.

  • #3 / Jun 06, 2009 7:20pm

    medic119

    52 posts

    I pretty straight forward on the index.  See below.  I want the tweet to appear as though it were just another article and not always at the top of my feed list like it is on the homepage.  I want it inline with the RSS articles.  I am just not sure how to do it right.  An EMBED, or what and how to format it.  I changed my RSS Template today (based on a nice template I found on a blog) to use CDATA instead of all XML/XHTML.

    It wasn’t an issue with the index because the tweet is stuck at the top of the article listings, outside the weblog:entries tag.

    
    
    

    RSS Updated

    {assign_variable:master_weblog_name="ffp"}
    {assign_variable:my_template_group="scrapbook"}
    {exp:rss:feed weblog="{master_weblog_name}"}
       <?xml version="1.0" encoding="{encoding}"?>
       <rss version="2.0"
          xmlns:dc="http://purl.org/dc/elements/1.1/"
          xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
          xmlns:admin="http://webns.net/mvcb/"
          xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns:content="http://purl.org/rss/1.0/modules/content/"
          xmlns:atom="http://www.w3.org/2005/Atom">
       <channel>
       {exp:weblog:entries weblog="{master_weblog_name}" limit="10" rdf="off" dynamic_start="on" disable="member_data|trackbacks|pagination"}
       <title>{exp:xml_encode}{site_name}{/exp:xml_encode}</title>
       <link>{site_url}</link>
       <description>The Journal of a Combat Medic</description>
       <dc:language>{weblog_language}</dc:language>
       <dc:rights>Copyright {gmt_date format="%Y"}</dc:rights>
       <dc:date>{gmt_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
       <admin:generatorAgent rdf:resource="http://expressionengine.com/" >
       <atom:link href="{site_url}system/rss20" rel="self" type="application/rss+xml" >
       <item>
       <title>{exp:xml_encode}{title}{/exp:xml_encode}</title>
       <dc:creator>{author}</dc:creator>
       <link>{title_permalink={my_template_group}/individual}{exp:xml_encode}{url_title}{/exp:xml_encode}</link>
       <guid>{title_permalink={my_template_group}/individual}{exp:xml_encode}#When:{gmt_entry_date format="%H:%i:%sZ"}{/exp:xml_encode}</guid>
       <description>
       <![CDATA[
       {body}
       {if extended}<a href="http://{title_permalink={my_template_group}/individual}">Continue Reading</a>{/if}
       <hr >
       Published in: {categories backspace="8"}<a href="http://{site_url}index.php/{my_template_group}/archive/category/{category_url_title}">{category_name}</a> • {/categories}
    
    Share: 
    
      <!-- FACEBOOK -->
    <a href="http://www.facebook.com/share.php?u={title_permalink={my_template_group}/individual}" target="_blank" rel="noopener">Facebook</a> • 
    
    <!-- DELICIOUS -->
    <a href="http://delicious.com/save">Delicious</a> • 
    
    <!-- DIGG -->
    <a href="http://digg.com/submit?phase=2&url={url_title_path=scrapbook/individual}&title={title}">Digg</a>
      ]]>
       </description>
       <dc:subject>{exp:xml_encode}{categories}{category_name}{/categories}{/exp:xml_encode}</dc:subject>
       <dc:date>{gmt_entry_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
       </item>
       {/exp:weblog:entries}
       </channel>
       </rss>
       {/exp:rss:feed}
  • #4 / Jun 08, 2009 7:38am

    bo-oz

    126 posts

    I think it will be kind of hard to place it inside the RSS feed if you wish to respect the publish date, for instance:

    entry 1
    entry 2
    tweet
    entry 3
    entry 4

    You could try to achieve this by comparing {gmt_date} (from {exp:weblog:entries}) to {created_at} (from {exp:twitter_timeline})

    Anyway.. you could easily create a RSS line like this:

    {exp:twitter_timeline type="user" user="ffpblog" password="password" limit="1"}
    <item>
    <dc:date>{created_at format=" %l, %F %d, %Y at %H:%i"}</dc:date>
    <title>{text}</title>
    </item>
    {/exp:twitter_timeline}
  • #5 / Jun 08, 2009 10:12am

    medic119

    52 posts

    Ok, this is what i cobbled together from your example and my own picking through of the RSS templates.  Problem is that right now, the LINK and GUID seem to append the site URL to the from of whatever is place between their tags, regardless of what I do.  I need that to point to the twitter page http://www.twitter.com/ffpblog instead of an internal template if at all possible.  Can I get around that restriction?  I searched the user guide, but it didn’t offer much help there.

    Also I am pretty sure its futzed up a little because I have two TITLE parameters listed.

    FYI the test feed is http://www.ffpblog.com/index.php/system/test

    Thanks again.

    {exp:twitter_timeline type="user" user="ffpblog" password="password" limit="1"}
    <item>
    <title>{exp:xml_encode}{site_name}{/exp:xml_encode}</title>
       <description>The Journal of a Combat Medic</description>
       <dc:language>{weblog_language}</dc:language>
       <dc:rights>Copyright {gmt_date format="%Y"}</dc:rights>
       <admin:generatorAgent rdf:resource="http://expressionengine.com/" >
       <atom:link href="{site_url}system/rss20" rel="self" type="application/rss+xml" >
       <dc:date>{created_at format=" %l, %F %d, %Y at %H:%i"}</dc:date>
    <link>{exp:xml_encode}Twitter link{/exp:xml_encode}</link>
    <guid>{exp:xml_encode}Twitter Link{/exp:xml_encode}</guid>
    <title>{exp:xml_encode}Far From Perfect Tweeted {created_at format=" %l, %F %d, %Y at %H:%i"}{/exp:xml_encode}</title>
    <description>{text}</description>
    </item>
    {/exp:twitter_timeline}
  • #6 / Jun 08, 2009 11:38am

    bo-oz

    126 posts

    There is a difference in the title of the RSS feed (which need to be placed first, before listing all <item>items</item>) and the title inside an <item> element. I do not know what’s wrong right now, or what you are trying to accomplish exactly. It seems your almost there though… what would you like to link your <guid> and <link> elements to? Do they need to link to your twitter account or to a internal part of your website?

    Wouldn’t it be a good idea to generate a seperate RSS feed for your tweets?

  • #7 / Jun 08, 2009 1:10pm

    medic119

    52 posts

    Twitter already provide RSS Feeds for the accounts.  The thing is I want my most recent tweet included in my RSS feed.  Most of the perople that read my site read it via RSS, and my twitter for the blog doesn’t update but maybe once a day so *another* RSS feed just seemed redundant and a detractor to usability.

    Yes, the GUID and LINK need to link directly to my twitter feed, but it seems EE has built it in that these elements automagically prepend the site URL to anything between them.  If it comes down to it I could link them to the Twitter template I created, but then that’s yet another click through to re-tweet, message, etc one of my tweets because twitter timeline doesn’t provide that functionality built in, and interaction is always the goal..😉 I could maybe create a template that is nothing but a forward to Twitter, but i’d like to see if its organically solvable first.

    Basically, if you took the twitter code above and inserted it right before the exp:weblog:entries tag (inside the CHANNEL tag) in the updated RSS Template above, you’d get the current template.  I duplicated the weblog:entries section to create the new section/item.  I don’t know what needs to be duplicated and what doesn’t.  The twitter timeline plugin doesn’t work inside the exp weblog entries tag that I know of, so I had to create a new section, not just a new item.

  • #8 / Jun 09, 2009 3:25am

    bo-oz

    126 posts

    You could ‘just’ include a (hardcoded) direct link to your twitter page, couldn’t you? That page always displays that exact same tweet at the time it is clicked:

    <guid>http://www.twitter.com/ffpblog</guid>
    <link>http://www.twitter.com/ffpblog</link>
  • #9 / Jun 09, 2009 3:30am

    bo-oz

    126 posts

    You could probably include your twitter part on the correct place by breaking up the {exp:weblog:entries} for a moment:

    {/exp:weblog:entries}
    {exp:twitter_timeline type="user" user="ffpblog" password="password" limit="1"}
    <item>
    <dc:date>{created_at format=" %l, %F %d, %Y at %H:%i"}</dc:date>
    <title>{text}</title>
    </item>
    {/exp:twitter_timeline} 
    {exp:weblog:entries same_parameters}

    This enables you to put it as the top item, instead of at the top of the overall RSS feed, you need to start with the meta_info in each RSS feed, followed by the various <item>‘s it contains.

  • #10 / Jun 09, 2009 6:17am

    medic119

    52 posts

    You could ‘just’ include a (hardcoded) direct link to your twitter page, couldn’t you? That page always displays that exact same tweet at the time it is clicked:

    <guid>http://www.twitter.com/ffpblog</guid>
    <link>http://www.twitter.com/ffpblog</link>

    Thanks for that.  I was actually creating the link instead of just putting the URL in there.  I learned something there. One problem solved

    You could probably include your twitter part on the correct place by breaking up the {exp:weblog:entries} for a moment:

    That doesn’t work.  It creates 10 headers, then the twee followed by 10 blog entries.  Neither the tweet not the entries has the properly formatted headers because they were broken up.

  • #11 / Jun 09, 2009 6:33am

    bo-oz

    126 posts

    There’s possibly no need for the {exp:weblog:entries} for the header (meta) part of the RSS:

    {exp:weblog:entries weblog="{master_weblog_name}" limit="10" rdf="off" dynamic_start="on" disable="member_data|trackbacks|pagination"}
       <title>{exp:xml_encode}{site_name}{/exp:xml_encode}</title>
       <link>{site_url}</link>
       <description>The Journal of a Combat Medic</description>
       <dc:language>{weblog_language}</dc:language>
       <dc:rights>Copyright {gmt_date format="%Y"}</dc:rights>
       <dc:date>{gmt_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
       <admin:generatorAgent rdf:resource="http://expressionengine.com/" >
       <atom:link href="{site_url}system/rss20" rel="self" type="application/rss+xml" >

    Could also be written as:

    {assign_variable:master_weblog_name="ffp"}
    {assign_variable:my_template_group="scrapbook"}
    {exp:rss:feed weblog="{master_weblog_name}"}
    
    <?xml version="1.0" encoding="{encoding}"?>
    <rss version="2.0"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
        xmlns:admin="http://webns.net/mvcb/"
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:content="http://purl.org/rss/1.0/modules/content/">
    
        <channel>
    
    // RSS meta header
       <title>{exp:xml_encode}{site_name}{/exp:xml_encode}</title>
       <link>{site_url}</link>
       <description>The Journal of a Combat Medic</description>
       <dc:language>{weblog_language}</dc:language>
       <dc:rights>Copyright {gmt_date format="%Y"}</dc:rights>
       <dc:date>{gmt_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
       <admin:generatorAgent rdf:resource="http://expressionengine.com/" >
       <atom:link href="{site_url}system/rss20" rel="self" type="application/rss+xml" >
    
    // Twitter part
    {exp:twitter_timeline type="user" user="ffpblog" password="password" limit="1"}
    <item>
    <dc:date>{created_at format=" %l, %F %d, %Y at %H:%i"}</dc:date>
    <title>{text}</title>
    </item>
    {/exp:twitter_timeline} 
    
    // Weblog:entries part
       {exp:weblog:entries weblog="{master_weblog_name}" limit="10" rdf="off" dynamic_start="on" disable="member_data|trackbacks|pagination"}
       <item>
       <title>{exp:xml_encode}{title}{/exp:xml_encode}</title>
       <dc:creator>{author}</dc:creator>
       <link>{title_permalink={my_template_group}/individual}{exp:xml_encode}{url_title}{/exp:xml_encode}</link>
       <guid>{title_permalink={my_template_group}/individual}{exp:xml_encode}#When:{gmt_entry_date format="%H:%i:%sZ"}{/exp:xml_encode}</guid>
       <description>
       <![CDATA[
       {body}
       {if extended}<a href="http://{title_permalink={my_template_group}/individual}">Continue Reading</a>{/if}
       <hr >
       Published in: {categories backspace="8"}<a href="http://{site_url}index.php/{my_template_group}/archive/category/{category_url_title}">{category_name}</a> • {/categories}
    
    Share: 
    
      <!-- FACEBOOK -->
    <a href="http://www.facebook.com/share.php?u={title_permalink={my_template_group}/individual}" target="_blank" rel="noopener">Facebook</a> •
    
    <!-- DELICIOUS -->
    <a href="http://delicious.com/save">Delicious</a> •
    
    <!-- DIGG -->
    <a href="http://digg.com/submit?phase=2&url={url_title_path=scrapbook/individual}&title={title}">Digg</a>
      ]]>
       </description>
       <dc:subject>{exp:xml_encode}{categories}{category_name}{/categories}{/exp:xml_encode}</dc:subject>
       <dc:date>{gmt_entry_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
       </item>
       {/exp:weblog:entries}
    
        </channel>
    </rss>
    
    {/exp:rss:feed}

    Edit: I’ve tried to copy/paste a real working template… try the code above

  • #12 / Jun 09, 2009 6:59am

    medic119

    52 posts

    That seems to work, although I am still restricted to the tweets at the top of the feed as the first item, but I may have to just live with that.

    Interesting thought.
    Am I going about this the wrong way?  Can I have mt Tweets automatically create an entry in the blog itself, say category “tweet?”  The the RSS would take care of itself.  Between the moblog module, Magpie, etc I wonder if there is a way.

    LG Twitter goes the other direction.  There are Twitter tools for Wordpress which essentially has this function (and would be an awesome port to EE).

  • #13 / Jun 09, 2009 7:42pm

    bo-oz

    126 posts

    In short, yes that would be possible, but I do not know if there are any extensions available for this. It would require regular polling of the Twitter API or RSS feed to check up on new tweets. After a new tweet is detected, the system should add the tweet as a weblog entry. I don’t think this is already available, especially since it doens’t have as much ‘value’ as the other way around imo.

    You could ofcourse use some custom PHP inside the RSS to determine where to place the tweet to make it appear in the correct position from a chronological perspective. But then again, are you sure you see the added value in integrating twitter inside your website RSS feed versus just linking to your Twitter RSS feed from your website?

  • #14 / Jun 09, 2009 9:13pm

    grrramps

    2219 posts

    Could you set up the RSS code to include conditionals?

    I have a few sites which required integrating multiple weblogs (which would be similar to a Twitter feed), some of which have different templates to link to, hence the need for a multi-level conditional.

  • #15 / Jun 11, 2009 2:54pm

    medic119

    52 posts

    I found FeedGrab which will pull the twitter feed and produce entries in a blog, which is almost perfect except for the limitations imposed by the twitter feed.

    The plugin takes the TITLE tag to parse the title of the entry.  Unfortunately Twitter posts the tweet in both the TITLE and DESCRIPTION tags, so using the TITLE as the title is not going to work.  The plugin doesn’t allow for custom titling either (I put in an FR but haven’t heard anything)

    Another limitation is pubDate.  That is a very long and full Date-Time stamp and the plugin doesn’t have a way to parse it down to a more readable format either.

    Lastly, the twitter feed parses the username to the beginning of the tweet ie: ffpblog:This is the tweet. The plugin doesn’t have a way to filter that out either..lol

    The plugin just parses feeds into entries and without the ability to do those thing above, its not gonna work, unfortunately.  I guess I need something like Twitter Tools plugin for Wordpress or a more specific plugin for twitter (and I have not the skill to build it).

    So back to square one.  I have for nw managed to include a proper RSS content portion for my tweets in my Feed though, and I thank you all for your continued help on this.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases