Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Frederik T 242 posts 373 karma points
    Apr 28, 2012 @ 22:19
    Frederik T
    0

    RSS Feeds and multiple document types

    Ok i know the solution for this is likely very simple, and i couldnt seem to find a solution after searching around so here goes:

    I see the general trend is to create an rss feed for each document type, like news, articles, announcements, events etc. But that would be overkill on my site, and i want a feed that can show entries for two different document types at the same time.

    I am using the bog standard RSS feed template built into umbraco, i have pasted the code in below which works just fine, but like i said, needs to support one or more document types:

    <xsl:param name="currentPage"/>

      <!-- Update these variables to modify the feed -->
      <xsl:variable name="RSSNoItems" select="string('10')"/>
      <xsl:variable name="RSSTitle" select="string('cuvkbh.dk')"/>
      <xsl:variable name="SiteURL" select="string('http://www.cuvkbh.dk')"/>
      <xsl:variable name="RSSDescription" select="string('Seneste nyheder og aktiviteter')"/>
      <xsl:variable name="rootNode" select="umbraco.library:GetXmlNodeById(1048)"/>


      <!-- This gets all news and events and orders by updateDate to use for the pubDate in RSS feed -->
      <xsl:variable name="pubDate">
        <xsl:for-each select="$rootNode/* [@isDoc]">
          <xsl:sort select="@createDate" data-type="text" order="descending" />
          <xsl:if test="position() = 1">
            <xsl:value-of select="updateDate" />
          </xsl:if>
        </xsl:for-each>
      </xsl:variable>

      <xsl:template match="/">
        <!-- change the mimetype for the current page to xml -->
        <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>

        <xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</xsl:text>
        <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/">

          <channel>
            <title>
              <xsl:value-of select="$RSSTitle"/>
            </title>
            <link>
              <xsl:value-of select="$SiteURL"/>
            </link>
            <pubDate>
              <xsl:value-of select="$pubDate"/>
            </pubDate>
            <generator>umbraco</generator>
            <description>
              <xsl:value-of select="$RSSDescription"/>
            </description>
            <language>da</language>

            <xsl:apply-templates select="$rootNode/descendant-or-self::NewsItem[@isDoc and string(umbracoNaviHide) != '1']">
              <xsl:sort select="@createDate" order="descending" />
            </xsl:apply-templates>
          </channel>
        </rss>

      </xsl:template>

      <xsl:template match="* [@isDoc]">
        <xsl:if test="position() &lt;= $RSSNoItems">
          <item>
            <title>
              <xsl:value-of select="@nodeName"/>
            </title>
            <link>
              <xsl:value-of select="$SiteURL"/>
              <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
            </link>
            <pubDate>
              <xsl:value-of select="umbraco.library:FormatDateTime(@createDate,'r')" />
            </pubDate>
            <guid>
              <xsl:value-of select="$SiteURL"/>
              <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
            </guid>
            <content:encoded>
              <xsl:value-of select="concat('&lt;![CDATA[ ', ./bodyText,']]&gt;')" disable-output-escaping="yes"/>
            </content:encoded>
          </item>
        </xsl:if>
      </xsl:template>
  • Frederik T 242 posts 373 karma points
    May 02, 2012 @ 14:47
    Frederik T
    0

    I apologize in advance, just one quick bump as i am sure it's a quick fix.

  • Frederik T 242 posts 373 karma points
    May 09, 2012 @ 13:28
    Frederik T
    0

    Final bump.

Please Sign in or register to post replies

Write your reply to:

Draft