Copied to clipboard

Flag this post as spam?

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


  • Evan 344 posts 99 karma points
    Jul 31, 2009 @ 17:09
    Evan
    2

    How to display the latest Blog Post (blog 4 umbraco) on homepage of website?

    How can I Display the latest Blog Post from my blog on the front page of my website?  I can't seem to get it working, I can display all of the posts but not the most recent one...

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 01, 2009 @ 00:27
    Sebastiaan Janssen
    5

    This is what I use to list the latest 3 blog posts. Of course you can change 3 to 1 ;)

     

    <?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: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 tagsLib BlogLibrary ">

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

    <xsl:param name="currentPage"/>
    <xsl:variable name="numberOfPosts" select="3"/>

    <xsl:template match="/">

    <xsl:for-each select="$currentPage/ancestor-or-self::node //node[@nodeTypeAlias = 'BlogPost']">
    <xsl:sort select="@createDate" order="descending" />
    <xsl:if test="position() = 1">
    <h2>Latest blog posts</h2>
    </xsl:if>
    <xsl:if test="position() &lt;= $numberOfPosts">
    <p><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></p>
    </xsl:if>
    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>
  • Evan 344 posts 99 karma points
    Aug 03, 2009 @ 16:11
    Evan
    0

    Great, thank for the response! worked like a charm

  • Kyle Skrinak 272 posts 327 karma points
    Feb 20, 2011 @ 01:30
    Kyle Skrinak
    0

    This xslt is the very code I need for the same reason Evan noted. However, using the StarterKit Blog and 4.6.1, it doesn't work. What changes should I make to get it working?

    Thanks!

  • Kyle Skrinak 272 posts 327 karma points
    Feb 20, 2011 @ 04:39
    Kyle Skrinak
    0

    It seems that this line:

      <xsl:for-each select="$currentPage/ancestor-or-self::root//node [@nodeTypeAlias='BlogPost']">

    Is failing to match anything. I do, however, have a doc type with an alias "BlogPost", what should I do?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 20, 2011 @ 06:32
    Jan Skovgaard
    0

    Hi Kyle

    Try creating a <textarea><xsl:copy-of select="$currentPage/ancestor-or-self::root//node [@nodeTypeAlias='BlogPost']" /></textarea> - does this return any XML at all?

    I guess there perhaps is a problem with your match...

    /Jan

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 20, 2011 @ 11:51
    Kim Andersen
    3

    Hi Kyle.

    There's probably no match because this XSLT is meant to be used with the legacy XML schema. Try this instead:

    <xsl:for-each select="$currentPage/ancestor-or-self::root//BlogPost">

    Does that help?

    /Kim A

  • Kyle Skrinak 272 posts 327 karma points
    Feb 20, 2011 @ 14:03
    Kyle Skrinak
    0

    Kim: did the trick; thanks!

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 20, 2011 @ 14:10
    Kim Andersen
    0

    Great to hear Kyle - You're welcome. I'm glad you got it working :)

    Have a nice day!

    /Kim A

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 20, 2011 @ 14:15
    Jan Skovgaard
    0

    D'oh! I obviously have not been fully waken when I answered earlier. You rock Kim! :-)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft