Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 09, 2011 @ 06:40
    Fuji Kusaka
    0

    Paging in Media Section

    I have an issue with my xslt paging. On the first page it displays the max number of items but when i click on the second page 1 Image adds itself. So instead of having 12 items on the second page i have 13 items.

    Item 13 repeats istelf on the third page as well. Any idea why am getting this?

  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 09, 2011 @ 07:26
    Fuji Kusaka
    0

     

    First Page am Getting the right output that is :12 

    Second Page getting : 13 where the last image on page 1 repeats itself on the second page

    The same issue applies to the other pages. Any thought on this please?

    <xsl:param name="currentPage"/>
       
    <xsl:variable name="mediaFolder" select="/macro/imgFiles"/>
    <xsl:variable name="itemsToDisplay" select="12"/>  
    <xsl:variable name="jump" select="$itemsToDisplay * $pageNumber" />

        
     <!-- Paging -->
    <xsl:variable name="pageNumber">
      <xsl:choose>
        <xsl:when test="umbraco.library:RequestQueryString('page') = ''">
         <xsl:value-of select="1"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>    

    <xsl:template match="/">
      <xsl:if test="$mediaFolder">   
        <xsl:variable name="mediaItems" select="umbraco.library:GetMedia($mediaFolder/*/@id, 'true')" />    
        <xsl:variable name="numImg" select="count($mediaItems/*[@id])"/>
         
        <ul>
          <xsl:for-each select="$mediaItems/Image"
            <xsl:if test="position() &lt;= $jump and position() &gt;= ($jump - $itemsToDisplay)">
              <li>
               <href="{concat(substring-before(umbracoFile,'.'),'_slideshow.jpg')}">
                 <xsl:attribute name="rel">
                      <xsl:value-of select="string('slideshow')"/>
                 </xsl:attribute>          
                 <xsl:attribute name="title">
                   <xsl:value-of select="@nodeName"/>
                 </xsl:attribute>
                 <img src="{concat(substring-before(umbracoFile,'.'),'_thumbnail.jpg')}" />           
             </a>
              </li>  
            </xsl:if>  
          </xsl:for-each>
        </ul>   
      
        <ul id="paging" style="margin-right:22px;">    
          <xsl:if test="$pageNumber &gt; 1">
            <li>
              <href="?page={$pageNumber -1}#page">&#171;  <xsl:value-of select="umbraco.library:GetDictionaryItem('previous')"/></a>
            </li>
          </xsl:if
          <xsl:call-template name="for.loop">
            <xsl:with-param name="i">1</xsl:with-param>
            <xsl:with-param name="count" select="ceiling($numImg div $itemsToDisplay)"></xsl:with-param>
          </xsl:call-template>  
        
          <xsl:if test="(($pageNumber) * $itemsToDisplay) &lt; ($numImg)">
            <li>
              <href="?page={$pageNumber+1}#page"<xsl:value-of select="umbraco.library:GetDictionaryItem('next')"/> &#187;</a>
            </li>
          </xsl:if
        </ul>
        
      </xsl:if>  
      </xsl:template>   
        
        <!-- Generate Pagination Numbers Loop -->
    <xsl:template name="for.loop">     
      <xsl:param name="i"/>
      <xsl:param name="count"/>              
      <xsl:if test="$i &lt;=$count">                     
        <xsl:if test="$pageNumber!= $i">
          <li>
            <href="?page={$i}#page"><xsl:value-of select="$i" /></a>
          </li>
        </xsl:if>

        <xsl:if test="$pageNumber = $i">
          <li>
            <xsl:value-of select="$i"/>
          </li>
        </xsl:if>
              
        <xsl:call-template name="for.loop">
          <xsl:with-param name="i" select="$i + 1" />
          <xsl:with-param name="count" select="$count">
          </xsl:with-param>
        </xsl:call-template>                  
      </xsl:if>
    </xsl:template>
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Nov 09, 2011 @ 09:03
    Chriztian Steinmeier
    0

    Hi Fuji,

    Two small changes will fix that:

    1. The $jump variable should be set to point to the first item of the "next" page, so add one to it:

    <xsl:variable name="jump" select="$itemsToDisplay * $pageNumber + 1" />

    2. Use less-than instead of less-than-equal-to in the test: 

    <xsl:if test="position() &lt; $jump and position() &gt;= ($jump - $itemsToDisplay)">

    3. There is no step 3 :-)

    /Chriztian

  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 10, 2011 @ 07:40
    Fuji Kusaka
    0

    Hi Chriztian,

    Thanks for the help. Works perfectly.

     

Please Sign in or register to post replies

Write your reply to:

Draft