Announcement

Collapse
No announcement yet.

Display/Output Position of Foreach loop - Top 10 products with rank number

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Display/Output Position of Foreach loop - Top 10 products with rank number

    Hello Miva People,

    I'm trying to figure out how to display/output the number position of products in a Foreach loop (Array). I'm using the best selling products code from toolkit and would like to list the top selling items current position . . . for example, lets say I want to do a top 10 best selling products page, I would like to output the number/rank position of each product.

    Please let me know if there is a way to accomplish this . . . I'm truly banging my head against the wall on this one lol. Any help or tips for helping me solve this problem would be GREATLY appreciated.

    Thanks Guys and Gals,
    ThePen

    #2
    Re: Display/Output Position of Foreach loop - Top 10 products with rank number

    Every foreach loop has a built in counter called pos1 (Which stands for position). You can conditionally test for this variable to do what you need.

    Code:
    <mvt:if pos1 LE 10>
    
    //output bestsellers
    
    </mvt:if>
    The reason it is called pos1 and not just pos, is if you have nested foreach loop the second loops counter is called pos2 and so on.

    Here are some docs on how this feature works:

    http://www.mivamerchant.com/videos/a...oops-with-pos1

    pos1 one cannot be directly output to the page. If you need to display its value you would could create your own counter to display.

    Code:
    <mvt:assign name="g.counter" value="1" />
    <mvt:foreach iterator="product" array="category_listing:products">
    Current Count: &mvt:global:counter;
    
    
    <mvt:assign name="g.counter" value="g.counter + 1" />
    </mvt:foreach>
    Last edited by Brennan; 01-18-14, 02:42 PM.
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Re: Display/Output Position of Foreach loop - Top 10 products with rank number

      You could also simply use <ol> and wrap the output of the foreach with <li>...viola! Numbers.
      Bruce Golub
      Phosphor Media - "Your Success is our Business"

      Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
      phosphormedia.com

      Comment

      Working...
      X