Copied to clipboard

Flag this post as spam?

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


  • Meni 271 posts 507 karma points
    Apr 29, 2013 @ 00:11
    Meni
    0

    Node offset - is it possible?

    Hello

    I want to display the first 8 / 10 items of each node (childrens) on home page.

    So I'm use the foreach loop as follow:

    @foreach (var newsItem in Imaging_pagesToList.Take(3))
                {
                    var selectedMedia = @newsItem.Media("articleImg");
                    <div class="news_box">
                        <div class="img_frame">
                            <a href="@newsItem.Url" class="img_link">
                                <img src="@selectedMedia.umbracoFile" width="140" height="100" alt="@selectedMedia.Name" />
                            </a>
                        </div>                    
                        <div class="news_frame">
                            <h2>
                                <a href="@newsItem.Url" class="news_link">
                                    @newsItem.title
                                </a>
                            </h2>
                            <p>
                                @newsItem.metaDescription       
                            </p>
                        </div>     
                        <div style="clear:both"></div>                                   
                    </div>
                    <!-- ************************** -->
                                  }                                   
    

    and then I use a second loop:

     <!-- ************************************************************** -->  
                    <div class="news_box">
    
                        @foreach (var newsItem in Imaging_pagesToList.Take(5))
                        {                       
    
                            <h2 class="entry_title_1">
                                <a href="@newsItem.Url" class="news_link">
                                       @newsItem.title 
                                </a>
                            </h2>
                        }        
                    </div> 

    However, I want that the second loop will begin from item number 5

    And then another loop for another two items which I like to begin from item number 8 of course

    As well as - I'm always want to show just the last 8 items - mean - the newst articles which added - how do I do it? 

    The offset 

    And also make sure I'm show just the latest articles (wach item is an article which added)

     

    Thanks

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 29, 2013 @ 00:56
    Tom Fulton
    0

    Hi,

    Is Skip what you're looking for?  If you want to start at item #5 and grab the next 5 nodes, you could try:

    Imaging_pagesToList.Skip(5).Take(5)

    To sort you can do something like:

    var sortedList = Imaging_pagesToList.OrderBy("createDate Desc")

    Hope this helps,
    Tom 

  • Meni 271 posts 507 karma points
    Apr 29, 2013 @ 01:28
    Meni
    0

    Thanks! work. about the second thing (showing just the latest articles) - is it possible to do it with out sorting? Like, how does the CMS store each node (page / article) that added? How does it order it? Is it possible do it with out new var / etc?

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 29, 2013 @ 01:40
    Tom Fulton
    0

    I think you're going to need to sort to get them in newest order.  By default, the nodes sort the same way they show in the backoffice (first to last in order added, but could be different if the user clicks Sort and changes things themselves).  So if you want to ensure you're getting the latest, you'll want to use OrderBy with whichever field you want to sort by (ie a custom date picker or createDate).

    You can certainly do it without the new var stuff, ie foreach (var item in Imaging_pagesToList.OrderBy("createDate desc").Take(5).Skip(5)) etc...

  • Meni 271 posts 507 karma points
    Apr 29, 2013 @ 20:41
    Meni
    0

    Thanks!!!! Work!!

Please Sign in or register to post replies

Write your reply to:

Draft