Copied to clipboard

Flag this post as spam?

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


  • Martin 278 posts 662 karma points
    Dec 06, 2011 @ 11:39
    Martin
    0

    News Item Associated with location

    Hi, 

    Im using the umbraco.tv news area, news item tutorial. 

    I have a site that has a general news area, but i would like to filter and show only relevent news articles based on shop location.

    Im still new to XSLT, so any help would be grateful

    my xslt for my news item is 


    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <!-- The fun starts here -->
    <xsl:for-each select="$currentPage [@isDoc and string(umbracoNaviHide) != '1']">
    <div class="twelve columns alpha">
      <h2 class="col newsHeadline">
          <xsl:value-of select="@nodeName"/>
      </h2>
      <xsl:if test="newsSummary != ''">
        <class="newsAuthor"><xsl:value-of select="newsAuthor" disable-output-escaping="yes"/></p>
      </xsl:if>    
        <class="newsDate"><xsl:value-of select="umbraco.library:FormatDateTime(@createDate, 'MMM d, yyyy')"/></p>
      <xsl:if test="newsArticle != ''">  
        <class="newsArticle"><xsl:value-of select="newsArticle" disable-output-escaping="yes"/></p>  
      </xsl:if>  
    </div>  

    </xsl:for-each>

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

    And my News Area is

    <xsl:param name="currentPage"/>
    <xsl:variable name="itemsPerPage" select="5"/>
    <xsl:variable name="numberOfItems" select="count($currentPage/* [@isDoc and string(umbracoNaviHide) != '1'])"/>
    <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>

    <!-- day -->    
    <xsl:variable name="newsDay">
      <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="/">

    <!-- The fun starts here -->
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
    <xsl:sort select="@createDate" order="descending"/>
    <xsl:if test="position() &gt; $itemsPerPage * number($pageNumber -1) and 
      position() &lt;= number($itemsPerPage * number($pageNumber -1) + $itemsPerPage)">
     
      <div class="twelve columns alpha clearfix">
        <h3 class="newsHeadline col">
          <href="{umbraco.library:NiceUrl(@id)}">
            <xsl:value-of select="@nodeName"/>
          </a>
        </h3>
        <xsl:value-of select="umbraco.library:LongDate(@createDate)"/>
        <p><xsl:value-of select="newsSummary" disable-output-escaping="yes"/></p>
      </div>
       
    </xsl:if>
    </xsl:for-each>

      
    <div class="twelve columns alpha paginator clearfix"
    <!-- PAGE NUMBERS -->  

    <xsl:if test="$pageNumber &gt; 1">
       <div class="one column" style="text-align:center;"
        <class="prev" href="?page={$pageNumber -1}">Prev</a>
        </div>
        </xsl:if>

        
    <xsl:call-template name="for.loop">
    <xsl:with-param name="i">1</xsl:with-param>
    <xsl:with-param name="count" select="ceiling($numberOfItems div $itemsPerPage)"></xsl:with-param>
    </xsl:call-template>
    <!-- NEXT BUTTON-->
         
    <xsl:if test="(($pageNumber) * $itemsPerPage) &lt; ($numberOfItems)">
    <div class="one column" style="text-align:center;">
      <class="next" href="?page={$pageNumber +1}">Next</a>
    </div>
    </xsl:if>

    </div>  
    </xsl:template>
      
    <xsl:template name="for.loop">
      
      <xsl:param name="i"/>
      <xsl:param name="count"/>
     
      <xsl:if test="$i &lt;= $count">
      
        <xsl:if test="$pageNumber != $i">
           <div class="one column" style="text-align:center;">
          <class="page" href="?page={$i}">
            <xsl:value-of select="$i" />
             </a></div>
        </xsl:if>


        <xsl:if test="$pageNumber = $i ">
            <div class="one column" style="text-align:center;">     
          <span>  <xsl:value-of select="$i" /></span>
          </div>
        </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>  


    </xsl:stylesheet>

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 06, 2011 @ 22:34
    Jan Skovgaard
    0

    Hi Martin

    What data for the shop location do you have available in Umbraco? Are you tagging the news by location using either the tag datatype or simply a checkbox? Or are you thinking of using longitude and latitude for instance to show news relevant to where the user is right now?

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft