Copied to clipboard

Flag this post as spam?

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


  • Pete Brown 47 posts 77 karma points
    Feb 24, 2010 @ 22:31
    Pete Brown
    0

    Blog4Umbraco 4 - BlogListPosts.xslt doesn't filter by month

    The BlogListPosts.xslt, included with Blog4Umbraco 4, doesn't include any code to filter by date. However, it is called from the date folders.

    Before I go and try and muddle through the xsl myself, anyone have a fix?

    Pete

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Feb 24, 2010 @ 22:34
    Douglas Robar
    102

    Try this...

    <?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:tagsLib="urn:tagsLib"
    xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
    xmlns:BlogLibrary="urn:BlogLibrary"
    exclude-result-prefixes="msxml umbraco.library tagsLib Exslt.ExsltStrings BlogLibrary">

    <!-- Updated 15-Feb-2010 by Percipient Studios to handle month archives properly. -->

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

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

    <xsl:variable name="pageNumber">
    <xsl:choose>
    <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:variable name="filter">
    <xsl:choose>
    <xsl:when test="string-length(umbraco.library:Request('filterby')) &gt; 0">
    <xsl:value-of select="umbraco.library:Request('filterby')"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="''"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:variable name="numberOfRecords">
    <xsl:choose>
    <xsl:when test="$currentPage/@nodeTypeAlias = 'DateFolder'">
    <xsl:value-of select="count($currentPage//node [@nodeTypeAlias = 'BlogPost'])"/>
    </xsl:when>
    <xsl:when test="$filter = ''">
    <xsl:value-of select="count($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']//node [@nodeTypeAlias = 'BlogPost'])"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="count($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']//node [@nodeTypeAlias = 'BlogPost' and contains(Exslt.ExsltStrings:lowercase(./data [@alias='tags']), Exslt.ExsltStrings:lowercase($filter))])"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:template match="/">


    <xsl:if test="$filter != ''">
    <h2 class="page-title">
    Archive for tag:
    <span>
    <xsl:value-of select="$filter"/>
    </span>
    </h2>
    </xsl:if>

    <xsl:if test="$currentPage/@nodeTypeAlias = 'DateFolder'">
    <h2 class="page-title">
    Monthly Archives: <xsl:value-of select="umbraco.library:FormatDateTime(concat($currentPage/../@nodeName,'-',$currentPage/@nodeName,'-11T10:24:46'),'MMMM yyyy')"/>
    </h2>
    </xsl:if>

    <xsl:if test="$numberOfRecords &gt; $numberOfPosts">
    <div id="nav-above" class="navigation">

    <div class="nav-previous">
    <xsl:if test="(($pageNumber ) * $numberOfPosts) &lt; ($numberOfRecords)">
    <span class="meta-nav">&#171; </span>
    <a href="?page={$pageNumber +1}">Older posts</a>
    </xsl:if>
    </div>

    <div class="nav-next">
    <xsl:if test="$pageNumber &gt; 1">
    <a href="?page={$pageNumber -1}">Newer posts</a>
    <span class="meta-nav"> &#187;</span>
    </xsl:if>
    </div>

    </div>
    <p>&nbsp;</p>
    </xsl:if>

    <xsl:if test="$filter = ''">

    <xsl:choose>
    <xsl:when test="$currentPage/@nodeTypeAlias = 'DateFolder'">
    <xsl:for-each select="$currentPage//node [@nodeTypeAlias = 'BlogPost']">
    <xsl:sort select="@createDate" order="descending" />
    <xsl:if test="position() &gt; $numberOfPosts * (number($pageNumber)-1) and
    position() &lt;= number($numberOfPosts * (number($pageNumber)-1) +
    $numberOfPosts )">
    <xsl:call-template name="showpost">
    <xsl:with-param name="post" select="."/>
    </xsl:call-template>
    </xsl:if>
    </xsl:for-each>


    </xsl:when>
    <xsl:otherwise>
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']//node [@nodeTypeAlias = 'BlogPost']">
    <xsl:sort select="@createDate" order="descending" />
    <xsl:if test="position() &gt; $numberOfPosts * (number($pageNumber)-1) and
    position() &lt;= number($numberOfPosts * (number($pageNumber)-1) +
    $numberOfPosts )">
    <xsl:call-template name="showpost">
    <xsl:with-param name="post" select="."/>
    </xsl:call-template>
    </xsl:if>
    </xsl:for-each>

    </xsl:otherwise>
    </xsl:choose>
    </xsl:if>

    <xsl:if test="$filter != ''">

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']//node [@nodeTypeAlias = 'BlogPost' and contains(Exslt.ExsltStrings:lowercase(./data [@alias='tags']), Exslt.ExsltStrings:lowercase($filter))]">
    <xsl:sort select="@createDate" order="descending" />
    <xsl:if test="position() &gt; $numberOfPosts * (number($pageNumber)-1) and
    position() &lt;= number($numberOfPosts * (number($pageNumber)-1) +
    $numberOfPosts )">
    <xsl:call-template name="showpost">
    <xsl:with-param name="post" select="."/>
    </xsl:call-template>
    </xsl:if>
    </xsl:for-each>
    </xsl:if>

    <div id="nav-below" class="navigation">

    <div class="nav-previous">
    <xsl:if test="(($pageNumber ) * $numberOfPosts) &lt; ($numberOfRecords)">
    <span class="meta-nav">&#171; </span>
    <a href="?page={$pageNumber +1}">Older posts</a>
    </xsl:if>
    </div>

    <div class="nav-next">
    <xsl:if test="$pageNumber &gt; 1">
    <a href="?page={$pageNumber -1}">Newer posts</a>
    <span class="meta-nav"> &#187;</span>
    </xsl:if>
    </div>

    </div>


    </xsl:template>

    <xsl:template name="showpost">
    <xsl:param name="post"/>

    <div class="hentry post publish author-{$post/@writername} tag-boat tag-lake {umbraco.library:FormatDateTime($post/@updateDate, 'yYYYY mMM')} y2008 m10 d17 h04">
    <h2 class="entry-title" id="post-{$post/@id}">
    <a href="{umbraco.library:NiceUrl($post/@id)}" title="Permalink to {$post/@nodeName}">
    <xsl:value-of select="$post/@nodeName"/>
    </a>
    </h2>

    <div class="entry-date">
    <abbr class="published" title="umbraco.library:ShortDate($post/@updateDate)">
    <xsl:value-of select="umbraco.library:LongDate($post/@updateDate)"/>
    </abbr>
    </div>


    <div class="entry-content">
    <xsl:value-of select="$post/data [@alias = 'bodyText']" disable-output-escaping="yes"/>
    </div>

    <div class="entry-meta">

    <span class="author vcard">
    By: <span class="fn n">
    <xsl:value-of select="$post/@creatorName"/>
    </span>
    </span>
    <span class="meta-sep"> |</span>
    <span class="tag-links">
    <xsl:variable name="tags" select="tagsLib:getTagsFromNode(@id)" />
    <xsl:choose>
    <xsl:when test="count($tags/tags/tag) = 0">
    Not tagged
    </xsl:when>
    <xsl:otherwise>
    Tagged:
    <xsl:for-each select="$tags/tags/tag">
    <a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']/@id)}?filterby={.}" rel="tag">
    <xsl:value-of select="."/>
    </a>
    <xsl:if test="position() != last()">, </xsl:if>
    </xsl:for-each>
    </xsl:otherwise>
    </xsl:choose>
    </span>
    <span class="meta-sep"> | </span>
    <xsl:variable name="numberofcomments" select="count(BlogLibrary:GetCommentsForPost($post/@id)//comment)"/>
    <span class="comments-link">
    <xsl:choose>
    <xsl:when test="$numberofcomments = 0">
    <xsl:choose>
    <xsl:when test="string($post/data [@alias = 'closeComments']) = '1'">
    Comments closed
    </xsl:when>
    <xsl:otherwise>
    <a href="{umbraco.library:NiceUrl(@id)}#comments">Leave comment</a>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:when>
    <xsl:when test="$numberofcomments = 1">
    <a href="{umbraco.library:NiceUrl(@id)}#comments">1 comment</a>
    </xsl:when>
    <xsl:otherwise>
    <a href="{umbraco.library:NiceUrl(@id)}#comments">
    <xsl:value-of select="$numberofcomments"/> comments
    </a>
    </xsl:otherwise>
    </xsl:choose>
    </span>
    </div>

    </div>
    </xsl:template>
    </xsl:stylesheet>

    cheers,
    doug.

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Feb 24, 2010 @ 22:36
    Douglas Robar
    0

    I should mention that this might be a slightly customized xslt, but the important bits for the date handling are there and you can grab them and incorporate into your own macro as needed.

    cheers,
    doug.

  • Pete Brown 47 posts 77 karma points
    Feb 24, 2010 @ 22:51
    Pete Brown
    0

    Brilliant! Thanks. That worked wonderfully.

    I went to mark the post as the answer, but there's no button for that. Odd.

    Pete

  • Pete Brown 47 posts 77 karma points
    Feb 24, 2010 @ 22:51
    Pete Brown
    0

    @Doug

    Mine was customized as well, which was why it took me a few minutes to parse your changes and incorporate them. Great stuff.

    Thanks again.

    Pete

  • Pete Brown 47 posts 77 karma points
    Feb 24, 2010 @ 22:52
    Pete Brown
    0

    Found the "mark as answer" button. It was way over to the right, in the position it would be if there were no scrollbars in your source code listing.

    I love browsers :P

    Pete

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Feb 24, 2010 @ 22:54
    Douglas Robar
    0

    Super!

    Feel free to make a codeplex issue and reference this post for the details/solution.

    As for being able to mark a post solved... I think you may need to have made a minimum number of posts before you can do that. 10 posts, maybe? I'm not sure what the current algorithm is.

    Whenever you get to that level please come back and mark any of your earlier posts' solutions for the benefit of the next person travelling the same road.

    cheers,
    doug.

  • Jamie Howarth 306 posts 773 karma points c-trib
    Feb 25, 2010 @ 00:17
    Jamie Howarth
    0

    I'm on Blog4 core and I'm adding some modifications to it, so I'll pick this one up. Thanks Doug :-)

    Best,

    Benjamin

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Feb 25, 2010 @ 00:49
    Douglas Robar
    0

    Excellent, thanks Benjamin!

    cheers,
    doug.

  • Andrew Blackmore 84 posts 127 karma points
    Jun 21, 2010 @ 13:31
    Andrew Blackmore
    0

    I just stumbled accross this after realizing the same thing myself (that Blog4 didn't actually deal with the dates in the archives). Huge help. Thanks doug.

  • Ast35 23 posts 44 karma points
    Jul 30, 2012 @ 15:38
    Ast35
    0

    I hope it is OK to bump this old thread, but I have tried that on 4.7.2, and it doesn't work.

    Is that because of the changes to the XSLT schema?

    I tried changing $currentPage/@nodeTypeAlias to local-name($currentPage)as described in the article below (in the original and the XSLT above), but the only change was that 'Monthly Archives: April 2012' was displayed, but no blog posts beneath it.

    http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/no-more-@nodetypealias

    Can anybody please point me to a version of the file which works with Umbraco 4.7.2, or explain to me what I need to change in the original XSLT or the script above to get it to filter by month correctly?

    Thanks.

  • Ast35 23 posts 44 karma points
    Jul 30, 2012 @ 16:52
    Ast35
    0

    OK, this seemed to do the trick for now. Please tell me if you spot any major problems with it.

    <?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:tagsLib="urn:tagsLib"
      xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
      xmlns:BlogLibrary="urn:BlogLibrary"
      exclude-result-prefixes="msxml umbraco.library tagsLib Exslt.ExsltStrings BlogLibrary">


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

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

      <xsl:variable name="pageNumber">
        <xsl:choose>
          <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:variable name="filter">
        <xsl:choose>
          <xsl:when test="string-length(umbraco.library:Request('filterby')) &gt; 0">
            <xsl:value-of select="umbraco.library:Request('filterby')"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="''"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:variable name="numberOfRecords">
        <xsl:choose>
          <xsl:when test="$filter = ''">
            <xsl:value-of select="count($currentPage/ancestor-or-self::Blog//BlogPost)"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="count($currentPage/ancestor-or-self::Blog//BlogPost [contains(Exslt.ExsltStrings:lowercase(./tags), Exslt.ExsltStrings:lowercase($filter))])"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:template match="/">


        <xsl:if test="$filter != ''">
          <h2 class="page-title">
            Archive for tag:
            <span>
              <xsl:value-of select="$filter"/>
            </span>
          </h2>
        </xsl:if>
        
        
        
       <!-- <xsl:if test="$currentPage/@nodeTypeAlias = 'DateFolder'">-->
        <xsl:if test="local-name($currentPage) = 'DateFolder'">
          <h2 class="page-title">
            Monthly Archives: <xsl:value-of select="umbraco.library:FormatDateTime(concat($currentPage/../@nodeName,'-',$currentPage/@nodeName,'-11T10:24:46'),'MMMM yyyy')"/>
          </h2>
        </xsl:if>

        <xsl:if test="$numberOfRecords &gt; $numberOfPosts">
        <div id="nav-above" class="navigation">

          <div class="nav-previous">
            <xsl:if test="(($pageNumber ) * $numberOfPosts) &lt; ($numberOfRecords)">
              <span class="meta-nav">&#171; </span>
              <a href="?page={$pageNumber +1}">Older posts</a>
            </xsl:if>
          </div>

          <div class="nav-next">
            <xsl:if test="$pageNumber &gt; 1">
              <a href="?page={$pageNumber -1}">Newer posts</a>
              <span class="meta-nav"> &#187;</span>
            </xsl:if>
          </div>

        </div>
        </xsl:if>
        
        <xsl:if test="$filter = ''">
     
          <xsl:for-each select="$currentPage/ancestor-or-self::Blog//BlogPost">
     
            <xsl:sort select="./PostDate" order="descending" />

            <xsl:if test="position() &gt; $numberOfPosts * (number($pageNumber)-1) and
            position() &lt;= number($numberOfPosts * (number($pageNumber)-1) +
            $numberOfPosts )">
              
              <xsl:call-template name="showpost">
                <xsl:with-param name="post" select="."/>
              </xsl:call-template>
          
            </xsl:if>
            
           </xsl:for-each>
        </xsl:if>

        <xsl:if test="$filter != ''">
    there is filter
          <xsl:for-each select="$currentPage/ancestor-or-self::Blog//BlogPost [contains(Exslt.ExsltStrings:lowercase(./tags), Exslt.ExsltStrings:lowercase($filter))]">
            <xsl:sort select="./PostDate" order="descending" />
            <xsl:if test="position() &gt; $numberOfPosts * (number($pageNumber)-1) and
            position() &lt;= number($numberOfPosts * (number($pageNumber)-1) +
            $numberOfPosts )">
              
              <xsl:call-template name="showpost">
                <xsl:with-param name="post" select="."/>
              </xsl:call-template>
            </xsl:if>
          </xsl:for-each>
        </xsl:if>

        <div id="nav-below" class="navigation">

          <div class="nav-previous">
            <xsl:if test="(($pageNumber ) * $numberOfPosts) &lt; ($numberOfRecords)">
              <span class="meta-nav">&#171; </span>
              <a href="?page={$pageNumber +1}">Older posts</a>
            </xsl:if>
          </div>

          <div class="nav-next">
            <xsl:if test="$pageNumber &gt; 1">
              <a href="?page={$pageNumber -1}">Newer posts</a>
              <span class="meta-nav"> &#187;</span>
            </xsl:if>
          </div>

        </div>


      </xsl:template>

      <xsl:template name="showpost">
        <xsl:param name="post"/>
        
        
     <xsl:variable name="DateFolderMonthYear" select="umbraco.library:FormatDateTime(concat($currentPage/../@nodeName,'-',$currentPage/@nodeName,'-11T10:24:46'),'MMMM yyyy')" />
     <xsl:variable name="PostMonthYear" select="umbraco.library:FormatDateTime($post/PostDate,'MMMM yyyy')"/>
        
        
       <xsl:if test="local-name($currentPage) != 'DateFolder' or $DateFolderMonthYear=$PostMonthYear">
        <div class="hentry post publish author-{$post/@writername} tag-boat tag-lake {umbraco.library:FormatDateTime($post/@updateDate, 'yYYYY mMM')} y2008 m10 d17 h04">
      

          <h2 class="entry-title" id="post-{$post/@id}">
            <a href="{umbraco.library:NiceUrl($post/@id)}" title="Permalink to {$post/@nodeName}">
              <xsl:value-of select="$post/@nodeName"/>
              
            </a>
          </h2>

          <div class="entry-date">
            <abbr class="published" title="umbraco.library:ShortDate($post/PostDate)">

              <xsl:value-of select="umbraco.library:LongDate($post/PostDate)"/>
            </abbr>
          </div>


          <div class="entry-content">
            <xsl:value-of select="$post/bodyText" disable-output-escaping="yes"/>
          </div>

          <div class="entry-meta">


      <!--      <span class="meta-sep"> |</span>
            <span class="tag-links">
              <xsl:variable name="tags" select="tagsLib:getTagsFromNode(@id)" />
              <xsl:choose>
                <xsl:when test="count($tags/tags/tag) = 0">
                  Not tagged
                </xsl:when>
                <xsl:otherwise>
                  Tagged:
                  <xsl:for-each select="$tags/tags/tag">
                    <a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::Blog/@id)}?filterby={.}" rel="tag">
                      <xsl:value-of select="."/>
                    </a>
                    <xsl:if test="position() != last()">, </xsl:if>
                  </xsl:for-each>
                </xsl:otherwise>
              </xsl:choose>
            </span>-->

            <xsl:variable name="numberofcomments" select="count(BlogLibrary:GetCommentsForPost($post/@id)//comment)"/>
            <span class="comments-link">
              <xsl:choose>
                <xsl:when test="$numberofcomments = 0">
                  <xsl:choose>
                    <xsl:when test="string($post/data [@alias = 'closeComments']) = '1'">

                    </xsl:when>

                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$numberofcomments = 1">
                  <a href="{umbraco.library:NiceUrl(@id)}#comments">1 comment</a>
                </xsl:when>
                <xsl:otherwise>
                  <a href="{umbraco.library:NiceUrl(@id)}#comments">
                    <xsl:value-of select="$numberofcomments"/> comments
                  </a>
                </xsl:otherwise>
              </xsl:choose>
            </span>
          </div>

        </div>
           </xsl:if>
      </xsl:template>
    </xsl:stylesheet>

Please Sign in or register to post replies

Write your reply to:

Draft