Copied to clipboard

Flag this post as spam?

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


  • Robert 63 posts 282 karma points
    Jan 22, 2015 @ 09:20
    Robert
    0

    Random all childs

    Hi there,

    I have a portfolio in the website and on the homepage there are 6 logo's displayed in a row. They will be random displayed. But now i get only the first 6 random displayed and let say the 7th item will not be shown at all. How can i manage to randomly display all the items but only show 6 of them...

    The code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        var homePage = CurrentPage.AncestorsOrSelf(1).First();
        var sliderOverview = homePage.OurWork.First();
        var contentSliders = sliderOverview.Section;
    }
    
    <div class="row">
    
            @foreach(var slide in contentSliders.Take(6).RandomOrder())
                {
                    if (slide.HasValue("customerLogo"))
                        {
                            var mediaFile = Umbraco.Media(slide.customerLogo);
                            <div class="col-md-2 col-sm-4 col-xs-6">
                                <div class="ourWorkImg">
                                    <img class="lazy" data-original="/ImageGen.ashx?image=@mediaFile.umbracoFile&amp;Compression=100&amp;width=130&amp;height=100&amp;constrain=true">
                                </div>
                            </div>
                        }
                }
    
            <div class="clearfix"></div>
    
        </div>
    

    Kind regards, Robert

  • Sören Deger 733 posts 2844 karma points c-trib
    Jan 22, 2015 @ 09:28
    Sören Deger
    100

    Hi Robert,

    this is behave logically.

    You take 6 items in contentSliders and after this you randomize the items.

    Change the position of "Take" and "RandomOrder" in your foreach to:

    @foreach(var slide in contentSliders.RandomOrder().Take(6))

    Hope this helps.

     

    Best,

    Sören

  • Robert 63 posts 282 karma points
    Jan 22, 2015 @ 10:07
    Robert
    0

    Hi Sören,

    Ah that sounds logical :)

    Thank you! Works perfect!

    Kind regards, Robert

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies