Copied to clipboard

Flag this post as spam?

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


  • Henrik Vincent 122 posts 616 karma points
    Jul 09, 2015 @ 08:54
    Henrik Vincent
    0

    Sorting by publish date

    Hi

    I've been working on splitting a multisite installation of Umbraco.

    I've manged to split the sites and upgrade em from Umbraco 4.7.2 to the newest version of v7.

    I'm having some trouble with the news section though, since our client often create news items and set the to publish later.

    I've tried Googling on wether it's possible to sort by publish date, but all posts I've found so far, tells that publishDate aren't in the XML cache and therefore can't sort by that parameter, but doesn't really seem to cover any fixes/hacks.

    Has anyone found a way to sort by publish date?

    I hope someone here can help me. Would be much appreciated!

    Henrik Vincent

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 09, 2015 @ 09:01
    Chriztian Steinmeier
    0

    Hi Henrik,

    You would need to write a custom extension for that, since the XML cache only contains published nodes, so there's no way for XSLT to get to that info...

    Probably better to use a Razor macro for it, since Razor has access to all the C# functions you'd need.

    Hope that helps,

    /Chriztian

  • Henrik Vincent 122 posts 616 karma points
    Jul 09, 2015 @ 10:34
    Henrik Vincent
    0

    Hi Chriztian

    Thanks for your reply.

    Is it possible to use Razor within an XLST file?

    The thing is, as I mentioned, the scripts from the old sites are all XSLT, since they date back to late 2011.

    I haven't really worked with Razor myself, since I got my certification back in '11, so haven't really used alot of Razor in my Umbraco "carreer".

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 09, 2015 @ 10:44
    Chriztian Steinmeier
    0

    Alright, that would be a mess - don't want to go there :)

    So have a look at this uComponents extension: GetReleaseDate()

    Supposedly, it will give you the date a piece of content is set to be published - mind you, that the nodeId you specify, you probably can't get from within XSLT, since (again) it isn't yet published :-)

    You could try to have a look at the actual source code for that extension, and see if you could write one yourself, that could help you do what you need.

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 09, 2015 @ 10:48
    Chriztian Steinmeier
    0

    But hey - are you sure that you don't just need the actual @createDate/@updateDate for sorting? - Are you not just rendering stuff in the frontend?

    /Chriztian

  • Henrik Vincent 122 posts 616 karma points
    Jul 09, 2015 @ 11:06
    Henrik Vincent
    0

    Not 100 % sure, no. I've had some problems understanding all of the code, the dev made back in the day.

    I've edited some of the code, to fit our clients wishes.

    This is the XSLT used for listing, sorting and paginating the news items.

    I've set up sorting to updateDate at the moment.

    ' ]>

    <xsl:include href="_PaginateIt.xslt"/>
    
    <xsl:param name="currentPage"/>
    
    <xsl:variable name="page" select="umbraco.library:RequestQueryString('page')" />
    
    <xsl:template match="/">
        <xsl:variable name="matchedNodes" select="$currentPage/descendant::*[@isDoc]" />
        <xsl:variable name="nodeCount" select="count($matchedNodes)" />
        <xsl:if test="$nodeCount &gt; 0">
            <xsl:variable name="page">
                <xsl:choose>
                    <!-- first page -->
                    <xsl:when test="number(umbraco.library:RequestQueryString('page')) &lt;= 1 or string(umbraco.library:RequestQueryString('page')) = '' or string(number(umbraco.library:RequestQueryString('page'))) = 'NaN'">
                        <xsl:value-of select="number('1')" />
                    </xsl:when>
                    <!-- last page -->
                    <xsl:when test="number(umbraco.library:RequestQueryString('page')) &gt; $nodeCount div $resultsPerPage">
                        <xsl:value-of select="ceiling($nodeCount div $resultsPerPage)" />
                    </xsl:when>
                    <!-- the value specified in the url -->
                    <xsl:otherwise>
                        <xsl:value-of select="number(umbraco.library:RequestQueryString('page'))"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <xsl:variable name="startMatch" select="($page - 1) * $resultsPerPage + 1" />
            <xsl:variable name="endMatch">
                <xsl:choose>
                    <!-- all the rest (on the last page) -->
                    <xsl:when test="($page * $resultsPerPage) &gt; $nodeCount">
                        <xsl:value-of select="$nodeCount" />
                    </xsl:when>
                    <!-- only the appropriate number for this page -->
                    <xsl:otherwise>
                        <xsl:value-of select="$page * $resultsPerPage" />
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
    
            <xsl:if test="$matchedNodes">
                <xsl:apply-templates select="$matchedNodes">
                    <xsl:sort select="@updateDate" order="descending" data-type="text" />
                    <xsl:with-param name="startMatch" select="$startMatch" />
                    <xsl:with-param name="endMatch" select="$endMatch" />
                </xsl:apply-templates>
            </xsl:if>
    
            <xsl:if test="$nodeCount &gt; $resultsPerPage">
                <xsl:call-template name="pagination">
                    <xsl:with-param name="page" select="$page" />
                    <xsl:with-param name="matchedNodes" select="$matchedNodes" />
                </xsl:call-template>
            </xsl:if>
    
        </xsl:if>
    
    </xsl:template>
    
    <xsl:template match="*[@isDoc]">
        <xsl:param name="startMatch" />
        <xsl:param name="endMatch" />
        <xsl:if test="position() &gt;= $startMatch and position() &lt;= $endMatch">
    
            <div class="post">
                <h3>
                      <a href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:attribute name="title"><xsl:value-of select="* [name() = 'pageHeadline']"/></xsl:attribute>
                        <xsl:value-of select="@nodeName"/>
                      </a>
                    </h3>
                <xsl:variable name="thumbsWidth" select="/macro/thumbsWidth" /> 
                <xsl:variable name="mediaId" select="number(* [name() = 'pageImage'])"/>
                <xsl:if test="$mediaId > 0">
                  <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
                  <xsl:if test="$mediaNode/umbracoFile">
                    <div class="listImage">
                      <img style="width:150px" src="{$mediaNode/umbracoFile}">
                        <xsl:attribute name="alt">
                          <xsl:choose>
                            <xsl:when test="* [name() = 'pageImageAltText'] != ''"><xsl:value-of select="* [name() = 'pageImageAltText']"/></xsl:when>
                            <xsl:otherwise><xsl:value-of select="$mediaNode/@nodeName"/></xsl:otherwise>
                          </xsl:choose> 
                        </xsl:attribute>
                      </img>
                    </div>
    
                  </xsl:if>
                </xsl:if>
    
                <xsl:choose>
                  <xsl:when test="listAbstract != ''"><xsl:value-of select="listAbstract" disable-output-escaping="yes" /></xsl:when>
                  <xsl:otherwise><xsl:value-of select="pageAbstract" disable-output-escaping="yes" /></xsl:otherwise>
    
                </xsl:choose>
                <xsl:value-of select="umbraco.library:FormatDateTime(@updateDate, 'dd-MM-yyyy')"/>
                <p class="readmore">&#187;&nbsp;<a href="{umbraco.library:NiceUrl(@id)}">L&#230;s resten af "<xsl:value-of select="pageHeadline"/>"</a></p>                                
    
                        </div>
    
            <hr />
        </xsl:if>
    </xsl:template>
    

    '

  • Henrik Vincent 122 posts 616 karma points
    Aug 10, 2015 @ 08:57
    Henrik Vincent
    101

    So I added a new property to the doctype with a Datepicker.

    In this I add the date, which should be the release date, and after this I changed the

Please Sign in or register to post replies

Write your reply to:

Draft