Copied to clipboard

Flag this post as spam?

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


  • Matteo Piazza 2 posts 22 karma points
    Jan 23, 2010 @ 22:11
    Matteo Piazza
    0

    Latest blog entries on homepage

    Hi! I am new to Umbraco and I have just installed Blog 4 Umbraco.

    My question is: is it possible to show the latest n blog entries on the homepage?

  • Paul Blair 466 posts 731 karma points
    Jan 23, 2010 @ 22:58
    Paul Blair
    0

    It is possible. This example will bring back 3 items:

      <xsl:param name="currentPage"/>
      <xsl:variable name="linkSource" select="$currentPage/data [@alias='newsSource']" />
      <xsl:variable name="newsSource" select="umbraco.library:GetXmlNodeById($linkSource)" />

      <xsl:template match="/">
          <xsl:for-each select="$newsSource//node [@nodeTypeAlias = 'BlogPost']">
            <xsl:sort select="./../../../@sortOrder" order="descending" />
            <xsl:sort select="./../../@sortOrder" order="descending" />
            <xsl:sort select="./../@nodeName" order="descending" />
            <xsl:sort select="@sortOrder" order="descending" />
            <xsl:if test="position()&lt;= 3">
              <div class="item">
                <h2>
                  <xsl:value-of select="@nodeName" />
                </h2>
                <xsl:value-of select="./data [@alias = 'bodyText']" disable-output-escaping="yes"/>
                <div class="date">
                  <p>
                    <xsl:value-of select="umbraco.library:FormatDateTime(concat(./../../../@nodeName,'-',./../../@nodeName,'-',./../@nodeName) , 'd MMM yyyy')" />
                  </p>
                </div>
                <div class="more">
                  <a href="{umbraco.library:NiceUrl(@id)}">More ></a>
                </div>
                <div class="clear">&nbsp;</div>
              </div>
            </xsl:if>
          </xsl:for-each>
      </xsl:template>
  • Matteo Piazza 2 posts 22 karma points
    Jan 23, 2010 @ 23:29
    Matteo Piazza
    0

    Thank you very much!!!

    I will try to implement your suggested solution as soon as I understand it!

  • Paul Blair 466 posts 731 karma points
    Jan 24, 2010 @ 00:51
    Paul Blair
    0

    ok, there may be a bit more there than you need. If you have any questions just ask.

    And during development I suggest hard-coding the newssource variable i.e.

    umbraco.library:GetXmlNodeById(1193)

    where 1193 is the node id for your blog

  • Andrew Blackmore 84 posts 127 karma points
    Feb 23, 2010 @ 22:06
    Andrew Blackmore
    0

    I'm a little bit late to the party but figured I'd add my insights...

     

    I had to do this with a bit more of a difficult example. I was pulling posts from 6 blogs that all needed to feed onto the homepage in chronological order. I altered the BlogListPosts.xslt and created a BlogListHomePosts.xslt

     

    I inserted this macro on the homepage template and every time I saw this line, or anything similr

     <xsl:value-of select="count($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']//node [@nodeTypeAlias = 'BlogPost'])"/>

    I changed it to

     <xsl:value-of select="count($currentPage/descendent-or-self::node [@nodeTypeAlias = 'Blog']//node [@nodeTypeAlias = 'BlogPost'])"/>

    This grabbed all the newest posts from every blog and spat them out onto the homepage. It worked quite nicely.

  • Chau 66 posts 97 karma points
    Apr 02, 2010 @ 22:53
    Chau
    0

    This worked very well for me. I did make a few changes so that it would work without the use of div tags. I needed to do this so that I could use it inside of jquery tools tabs which don't like the extra divs.

      <xsl:param name="currentPage"/>

      <xsl:variable name="newsSource" select="umbraco.library:GetXmlNodeById(1437)" />
      <xsl:variable name="allowable-length" select="165"/>
      <xsl:template match="/">
        <xsl:for-each select="$newsSource//node [@nodeTypeAlias = 'BlogPost']">
          <xsl:sort select="./../../../@sortOrder" order="descending" />
          <xsl:sort select="./../../@sortOrder" order="descending" />
          <xsl:sort select="./../@nodeName" order="descending" />
          <xsl:sort select="@sortOrder" order="descending" />
          <xsl:if test="position()&lt;= 1">
           <strong> <xsl:value-of select="@nodeName" /></strong> - <xsl:value-of select="umbraco.library:FormatDateTime(concat(./../../../@nodeName,'-',./../../@nodeName,'-',./../@nodeName) , 'd MMM yyyy')" /> - <a href="{umbraco.library:NiceUrl(@id)}">More</a>
            <p>
        <xsl:value-of select="substring(./data [@alias = 'bodyText'], 1, $allowable-length)" disable-output-escaping="yes"/>
        <xsl:if test="string-length(.) &gt; $allowable-length">
              <xsl:text>...</xsl:text>
        </xsl:if>
      </p>
          </xsl:if>
        </xsl:for-each>
      </xsl:template>

    I also added a truncating effect so that it works well as a summary. Thanks for all of your help!

    Cheers

  • Chau 66 posts 97 karma points
    Apr 02, 2010 @ 23:43
    Chau
    0

    Ok so I updated it even more to remove any html tags for consistant presentation.

      <xsl:param name="currentPage"/>
      <xsl:variable name="newsSource" select="umbraco.library:GetXmlNodeById(1437)" />
      <xsl:variable name="allowable-length" select="165"/>
      <xsl:template name="removeHtmlTags">
        <xsl:param name="html"/>
        <xsl:choose>
          <xsl:when test="contains($html, '&lt;')">
            <xsl:value-of select="substring-before($html, '&lt;')"/>
            <!-- Recurse through HTML -->
            <xsl:call-template name="removeHtmlTags">
              <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$html"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>
      <xsl:template match="/">
        <xsl:for-each select="$newsSource//node [@nodeTypeAlias = 'BlogPost']">
          <xsl:sort select="./../../../@sortOrder" order="descending" />
          <xsl:sort select="./../../@sortOrder" order="descending" />
          <xsl:sort select="./../@nodeName" order="descending" />
          <xsl:sort select="@sortOrder" order="descending" />
          <xsl:if test="position()&lt;= 1">
            <xsl:variable name="textOnly">
              <xsl:call-template name="removeHtmlTags">
                <xsl:with-param name="html" select="./data [@alias = 'bodyText']" />
              </xsl:call-template>
            </xsl:variable>
            <strong><xsl:value-of select="@nodeName" /></strong> - <xsl:value-of select="umbraco.library:FormatDateTime(concat(./../../../@nodeName,'-',./../../@nodeName,'-',./../@nodeName) , 'd MMM yyyy')" /> - <a href="{umbraco.library:NiceUrl(@id)}">More</a>
              <p>
        <xsl:value-of select="substring($textOnly, 0, $allowable-length)" disable-output-escaping="yes"/>
        <xsl:if test="string-length(.) &gt; $allowable-length">
                <xsl:text>...</xsl:text>
            </xsl:if>
      </p>
          </xsl:if>
        </xsl:for-each>
      </xsl:template>
  • Chau 66 posts 97 karma points
    Apr 18, 2010 @ 17:15
    Chau
    0

    One last fix. Because blog for umbraco creates a directory structure like 2010 > 4 > 3 and not 2010 > 04 > 03 when you list the directory contents it list it alphabetically like 1, 10, 2, 3, 4 when it needs to be 1, 2, 3, 4, 10. If we change a couple of lines everything turns out ok:

          <xsl:sort select="./../../../@sortOrder" order="descending" data-type="number" />
          <xsl:sort select="./../../@sortOrder" order="descending" data-type="number" />
          <xsl:sort select="./../@nodeName" order="descending" data-type="number" />
          <xsl:sort select="@sortOrder" order="descending" data-type="number" />

  • Chau 66 posts 97 karma points
    May 03, 2010 @ 06:32
    Chau
    0

    Wow one last entry. So I made this change so that the data on the main homepage ALWAYS shows in numeric order rather than the node sortOrder ID.

          <xsl:sort select="./../../../@nodeName" order="descending" data-type="number" />
          <xsl:sort select="./../../@nodeName" order="descending" data-type="number" />
          <xsl:sort select="./../@nodeName" order="descending" data-type="number" />
          <xsl:sort select="@nodeName" order="descending" data-type="number" />

    Cheers

  • Duncan Gunn 7 posts 30 karma points
    Sep 04, 2010 @ 19:13
    Duncan Gunn
    0

    Hello

     

    I was wondering if anyone had updated this to the 4.5.2 schema yet - I'm spanking new to Umbraco (picking it up very quickly - it's awesome) but can't get this to work and wondering if it is because its out of date?

     

    Thanks in advance!

  • Duncan Gunn 7 posts 30 karma points
    Sep 04, 2010 @ 21:49
    Duncan Gunn
    2

    Managed to crack it already, here is the code if anyone is interested (lists 3 blog posts on the home page):

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:uForum="urn:uForum" xmlns:uForum.raw="urn:uForum.raw" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets uForum uForum.raw tagsLib BlogLibrary ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>



    <xsl:param name="currentPage"/>
      <xsl:variable name="newsSource" select="umbraco.library:GetXmlNodeById(NODE ID OF YOUR BLOG NODE)" />
      <xsl:variable name="allowable-length" select="165"/>
      <xsl:template name="removeHtmlTags">
        <xsl:param name="html"/>
        <xsl:choose>
          <xsl:when test="contains($html, '&lt;')">
            <xsl:value-of select="substring-before($html, '&lt;')"/>
            <!-- Recurse through HTML -->
            <xsl:call-template name="removeHtmlTags">
              <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$html"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>
      <xsl:template match="/">
        <xsl:for-each select="$newsSource/descendant-or-self::* [@isDoc and name() = 'BlogPost']">
          <xsl:sort select="./../../../@sortOrder" order="descending" />
          <xsl:sort select="./../../@sortOrder" order="descending" />
          <xsl:sort select="./../@nodeName" order="descending" />
          <xsl:sort select="@sortOrder" order="descending" />
          <xsl:if test="position()&lt;= HOW MANY DO YOU WANT TO DISPLAY?">
            <xsl:variable name="textOnly">
              <xsl:call-template name="removeHtmlTags">
                <xsl:with-param name="html" select="./bodyText" />
              </xsl:call-template>
            </xsl:variable>
            <h3><xsl:value-of select="@nodeName" /></h3><xsl:value-of select="umbraco.library:FormatDateTime(concat(./../../../@nodeName,'-',./../../@nodeName,'-',./../@nodeName) , 'd MMM yyyy')" /> <href="{umbraco.library:NiceUrl(@id)}">Read More</a>
              <p>
        <xsl:value-of select="substring($textOnly, 0, $allowable-length)" disable-output-escaping="yes"/>
        <xsl:if test="string-length(.) &gt; $allowable-length">
                <xsl:text>...</xsl:text>
            </xsl:if>
      </p>
          </xsl:if>
        </xsl:for-each>
      </xsl:template>
      
      
      

    </xsl:stylesheet>

     

     

     

  • suzyb 464 posts 877 karma points
    Dec 02, 2010 @ 15:18
    suzyb
    0

    Thanks for that Duncan :D

  • Biagio Paruolo 1494 posts 1635 karma points c-trib
    Dec 07, 2010 @ 10:49
    Biagio Paruolo
    0

    And latest comments from blog? Is it possible via LINQ?

  • Rich Green 2246 posts 4006 karma points
    Dec 07, 2010 @ 18:25
    Rich Green
    0

    Hey Biagio,

    The comments are held in a standard SQL Server table (for some reason?) , so you could use Linq in the normal way I imagine.

    Rich

  • tesuji 95 posts 139 karma points
    Jul 22, 2011 @ 20:57
    tesuji
    0

    Duncan Gunn, thanks. Awesome code. 

    In case other people are newbies like me, put Duncan's code in a macro, and then there are a couple values you need to replace in the code - you'll see what I mean.

  • Bobby Wallace 37 posts 58 karma points
    Jan 07, 2012 @ 19:06
    Bobby Wallace
    0

    The good news is - the page loads. The bad news is, my list of blog entries is not being displayed. I'm using 4.7.1, and I've copied Duncan's as shown here:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:uForum="urn:uForum" xmlns:uForum.raw="urn:uForum.raw" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets uForum uForum.raw tagsLib BlogLibrary ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
      <xsl:variable name="newsSource" select="umbraco.library:GetXmlNodeById(1068)" />
      <xsl:variable name="allowable-length" select="165"/>
      <xsl:template name="removeHtmlTags">
        <xsl:param name="html"/>
        <xsl:choose>
          <xsl:when test="contains($html, '&lt;')">
            <xsl:value-of select="substring-before($html, '&lt;')"/>
            <!-- Recurse through HTML -->
            <xsl:call-template name="removeHtmlTags">
              <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$html"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>

        <xsl:template match="/">
        <xsl:for-each select="$newsSource/descendant-or-self::* [@isDoc and name() = 'BlogPost']">
          <xsl:sort select="./../../../@sortOrder" order="descending" />
          <xsl:sort select="./../../@sortOrder" order="descending" />
          <xsl:sort select="./../@nodeName" order="descending" />
          <xsl:sort select="@sortOrder" order="descending" />
          <xsl:if test="position()&lt;= 3">
            <xsl:variable name="textOnly">
              <xsl:call-template name="removeHtmlTags">
                <xsl:with-param name="html" select="./bodyText" />
              </xsl:call-template>
            </xsl:variable>
            <h3>
              <xsl:value-of select="@nodeName" /></h3><xsl:value-of select="umbraco.library:FormatDateTime(concat(./../../../@nodeName,'-',./../../@nodeName,'-',./../@nodeName) , 'd MMM yyyy')" /> <href="{umbraco.library:NiceUrl(@id)}">Read More</a>
                <p>
                  <xsl:value-of select="substring($textOnly, 0, $allowable-length)" disable-output-escaping="yes"/>
                  <xsl:if test="string-length(.) &gt; $allowable-length">
                    <xsl:text>...</xsl:text>
                  </xsl:if>
                </p>
          </xsl:if>
        </xsl:for-each>
      </xsl:template>
    </xsl:stylesheet>

    Thanks in advance...

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies