Copied to clipboard

Flag this post as spam?

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


  • Peter Drayton 29 posts 49 karma points
    Dec 21, 2011 @ 14:14
    Peter Drayton
    0

    Pagination

    Hi,

    I have some Pagination which is working wonderfully, displaying 5 items per Page.

    However, the Project Manager now wants there only to be 4 items on the firstpage and 5 on all subsequent pages.

    Does anyone have any ideas on how this can be achieved?

     

    Many thanks,

     

    Peter.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Dec 21, 2011 @ 14:39
    Chriztian Steinmeier
    0

    Hi Peter,

    That sounds really funny :-) I'm sure there's a reason for it, though.

    Start by checking your pagination logic to see if you can't just make some special-case for page 1 - one thing you might be able to take advantage of, is that nodes start at position 1, so you may just do all the calculations in groups of 5, starting at 0 - that way, your first page will only have 4 items (because index zero is nothing).

    Otherwise, show some of your XSLT so we have a better way of helping you.

    /Chriztian 

  • Peter Drayton 29 posts 49 karma points
    Dec 21, 2011 @ 14:52
    Peter Drayton
    0

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"><!ENTITY laquo "&#171;"><!ENTITY raquo "&#187;"> ]>
    <xsl:stylesheet version="1.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fb="http://www.facebook.com/2008/fbml" 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:umbraco.contour="urn:umbraco.contour" 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 umbraco.contour tagsLib BlogLibrary ">
    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
    <xsl:variable name="recordsPerPage" 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'">
          0
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="numberOfRecords" select="count(umbraco.library:GetXmlNodeById(1064)//*[@isDoc][not(self::DateFolder)])"/>
    <xsl:variable name="excerptLength">
      <xsl:choose>
        <xsl:when test="string(/macro/excerptLength) != ''">
          <xsl:value-of select="/macro/excerptLength"/>
        </xsl:when>
        <xsl:otherwise>130</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>  

    <xsl:template match="/">

      <xsl:for-each select="umbraco.library:GetXmlNodeById(1064)//*[@isDoc][not(self::DateFolder)]">
        <xsl:sort select="./articleDate" order="descending" />
        <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber) and position() &lt;= number($recordsPerPage * number($pageNumber) + $recordsPerPage )">
          <xsl:choose>
            <xsl:when test="position() = 1">
        <div class="social-hover">
              <div id="heroImage">
                <xsl:variable name="image" select="./heroImage"/>
                <xsl:if test="$image != ''">
                    <xsl:variable name="media" select="umbraco.library:GetMedia($image, 0)" />
                      <a href="{umbraco.library:NiceUrl(@id)}">
                        <img width="646" height="394" alt="{@nodeName}" src="{$media/umbracoFile}" />
                      </a>
                </xsl:if>
              </div>
              <h1 class="headline">
                  <a href="{umbraco.library:NiceUrl(@id)}">
                      <xsl:value-of select="headline" disable-output-escaping="yes"/>
                  </a>
              </h1>
              <div id="heroSeparator">&nbsp;</div>
              <div class="articleDetails">
                <span class="articleBy">By
                  <xsl:for-each select="writtenBy">
                    <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById(.)"/>
                    <xsl:value-of select="$currentNode/@nodeName"/>
                  </xsl:for-each>
                </span>
                <span class="articleDate">
                  <xsl:variable name="dte" select="number(umbraco.library:FormatDateTime(./articleDate, 'dd'))"/>
                  <xsl:variable name="endings" select="umbraco.library:Split('st,nd,rd,th,th,th,th,th,th,th,th,th,th,th,th,th,th,th,th,th,st,nd,rd,th,th,th,th,th,th,th,st',',')"/>
                  <xsl:value-of select="concat($dte,$endings/value[number($dte)]/text())"/>
                  <xsl:value-of select="umbraco.library:FormatDateTime(./articleDate,' MMMM yyyy')"/>
                </span>
              </div>
              <p class="heroText">
                <xsl:variable name="text" select="topText"/>
                <xsl:choose>
                  <xsl:when test="$text != ''">
                    <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml($text), 300, '...')" disable-output-escaping="yes"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(bodyText),300, '...')" disable-output-escaping="yes"/>
                  </xsl:otherwise>
                </xsl:choose>
              </p>
              <div class="social-bookmarks">
                <xsl:variable name="socialLink" select="umbraco.library:NiceUrl(./@id)"/>
                <div class="comments">
                  <a href="http://meerkovian.dev.themill.com{umbraco.library:NiceUrl(./@id)}#comments">
                  <div class="counter">
                    <fb:comments-count href="{umbraco.library:NiceUrl(./@id)}" class=" fb_comments_count_zero">
                      <span class="fb_comments_count">0</span>
                    </fb:comments-count>
                  </div>
                  </a>
                </div>
                  <div class="facebook">
                      <fb:like href="http://meerkovian.dev.themill.com{umbraco.library:NiceUrl(./@id)}" send="false" layout="button_count" width="100" show_faces="false"></fb:like>
                  </div>
                  <div class="twitter">
                      <a class="twitter-share-button" data-count="horizontal">
                        <xsl:attribute name="href">https://twitter.com/share?url=<xsl:value-of select="//siteURL" disable-output-escaping="yes"/><xsl:value-of select="$socialLink" disable-output-escaping="yes"/></xsl:attribute>
                          Tweet
                      </a>


                  </div>
                  <div class="gplus">
                      <g:plusone annotation="none" size="medium">
                        <xsl:attribute name="href"><xsl:value-of select="//siteURL" disable-output-escaping="yes"/><xsl:value-of select="$socialLink" disable-output-escaping="yes"/></xsl:attribute>
                      </g:plusone>
                  </div>
              </div>  
              <a href="{umbraco.library:NiceUrl(@id)}" class="readMore">Read more</a>
        </div>
              <div class="contentSeperator">&nbsp;</div>
            </xsl:when>
            <xsl:otherwise>
              <div class="post social-hover">
                <div class="postLeft">
                  <div class="thumbnail">
                <xsl:variable name="image" select="./heroImage"/>
                  <xsl:if test="$image != ''">              
                    <xsl:variable name="media" select="umbraco.library:GetMedia($image, 0)" />
                      <a href="{umbraco.library:NiceUrl(@id)}">
                        <img width="307" height="187" alt="{@nodeName}" src="{$media/umbracoFile}" />
                      </a>
                    </xsl:if>
                  </div>
                  <div class="social-bookmarks">
                    <xsl:variable name="socialLink" select="umbraco.library:NiceUrl(./@id)"/>
                    <div class="comments">
                      <a href="{umbraco.library:NiceUrl(./@id)}#comments">
                        <div class="counter">
                          <fb:comments-count href="{umbraco.library:NiceUrl(./@id)}" class=" fb_comments_count_zero">
                            <span class="fb_comments_count">0</span>
                          </fb:comments-count>
                        </div>
                      </a>
                    </div>    
                    <div class="facebook">
                      <fb:like href="http://meerkovian.dev.themill.com{umbraco.library:NiceUrl(./@id)}" send="false" layout="button_count" width="100" show_faces="false"></fb:like>
                    </div>
                    <div class="twitter">
                        <a class="twitter-share-button" data-count="horizontal">
                          <xsl:attribute name="href">https://twitter.com/share?url=<xsl:value-of select="//siteURL" disable-output-escaping="yes"/><xsl:value-of select="$socialLink" disable-output-escaping="yes"/></xsl:attribute>
                            Tweet
                        </a>                    
                        
                     
                    </div>
                      <div class="gplus">
                          <g:plusone annotation="none" size="medium">
                            <xsl:attribute name="href"><xsl:value-of select="//siteURL" disable-output-escaping="yes"/><xsl:value-of select="$socialLink" disable-output-escaping="yes"/></xsl:attribute>
                          </g:plusone>
                      </div>
                  </div>              
                </div>
                <div class="postRight">
                  <h3>
                      <a href="{umbraco.library:NiceUrl(./@id)}#comments">
                          <xsl:value-of select="headline" disable-output-escaping="yes"/>
                      </a>
                  </h3>
                  <div class="articleDetails">
                    <span class="articleBy">By
                      <xsl:for-each select="writtenBy">
                        <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById(.)"/>
                        <xsl:value-of select="$currentNode/@nodeName"/>
                      </xsl:for-each>
                    </span>
                    <span class="articleDate">
                      <xsl:variable name="dte" select="number(umbraco.library:FormatDateTime(./articleDate, 'dd'))"/>
                      <xsl:variable name="endings" select="umbraco.library:Split('st,nd,rd,th,th,th,th,th,th,th,th,th,th,th,th,th,th,th,th,th,st,nd,rd,th,th,th,th,th,th,th,st',',')"/>
                      <xsl:value-of select="concat($dte,$endings/value[number($dte)]/text())"/>
                      <xsl:value-of select="umbraco.library:FormatDateTime(./articleDate,' MMMM yyyy')"/>                  
                    </span>
                  </div>
                  <p>
                    <xsl:variable name="text" select="topText"/>
                    <xsl:choose>
                      <xsl:when test="$text != ''">
                        <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml($text), number($excerptLength), '...')" disable-output-escaping="yes"/>
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(bodyText), number($excerptLength), '...')" disable-output-escaping="yes"/>
                      </xsl:otherwise>
                    </xsl:choose>                
                  </p>
                  <a href="{umbraco.library:NiceUrl(@id)}" class="readMore">Read more</a>
                </div>
              </div>
              <div class="contentSeperator">&nbsp;</div>
          </xsl:otherwise>
        </xsl:choose>


        </xsl:if>
      </xsl:for-each>

      <div id="pagingDiv">
        <ul id="paging">
          <xsl:if test="$pageNumber &gt; 0">
            <li class="prev"><a href="?page={$pageNumber - 1}" class="text">Prev</a></li>
          </xsl:if>
          <xsl:variable name="newsPosts" select="count(umbraco.library:GetXmlNodeById(1064)//*[@isDoc][not(self::DateFolder)])"/>
          <xsl:call-template name="for.loop">
            <xsl:with-param name="i">1</xsl:with-param>
            <xsl:with-param name="page" select="$pageNumber + 1"></xsl:with-param>
            <xsl:with-param name="count" select="ceiling($newsPosts div 5)"></xsl:with-param>
          </xsl:call-template>
          <xsl:if test="(($pageNumber+1) * $recordsPerPage) &lt; ($numberOfRecords)">
            <li class="next"><a href="?page={$pageNumber+1}" class="text">Next</a></li>
          </xsl:if>
        </ul>
      </div>

    </xsl:template>

    <xsl:template name="for.loop">
      <xsl:param name="i"/>
      <xsl:param name="count"/>
      <xsl:param name="page"/>
      <xsl:if test="$i &lt;= $count">
        <xsl:if test="$page != $i">
          <li>
            <a href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i - 1}" >
              <xsl:value-of select="$i" />
            </a>
          </li>
        </xsl:if>
        <xsl:if test="$page = $i">
          <li class="active">
            <xsl:value-of select="$i" />
          </li>
        </xsl:if>
      </xsl:if>

      <xsl:if test="$i &lt;= $count">
        <xsl:call-template name="for.loop">
          <xsl:with-param name="i">
            <xsl:value-of select="$i + 1"/>
          </xsl:with-param>
          <xsl:with-param name="count">
            <xsl:value-of select="$count"/>
          </xsl:with-param>
          <xsl:with-param name="page">
            <xsl:value-of select="$page"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:if>

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

  • Peter Drayton 29 posts 49 karma points
    Dec 21, 2011 @ 16:47
    Peter Drayton
    0

    Anyone with any ideas?

    My position() always seems to be one record out on the second page.

Please Sign in or register to post replies

Write your reply to:

Draft