Copied to clipboard

Flag this post as spam?

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


  • NiQ 24 posts 45 karma points
    Nov 07, 2011 @ 12:17
    NiQ
    0

    Group pages by Month in creationDate and loop foreach?

    I want to make a list with all my news items where the posts are grouped by month so I got:

    January
    February
    March
    ....

    I know how to make a foreach loop with all Children but I have no clue how I make a distinct selection by only the month.

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Nov 07, 2011 @ 12:31
    Sebastiaan Janssen
    0

    Can you please show us what your nodestructure looks like at the moment?

    News
     - item 1
     - item 2

    or maybe
    News
     - 2011-10-02
       - item 1 
     - 2011-09-29
       - item 2 

  • NiQ 24 posts 45 karma points
    Nov 07, 2011 @ 13:45
    NiQ
    0

    Sure! It looks like this:

    News 
      - item 1 
      - item 2 
      - item 3
      - etc... 

  • Rajeev 126 posts 154 karma points
    Nov 07, 2011 @ 14:12
    Rajeev
    0

    NiQ,

    Could you try out this.

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
    //current month value to compare
    string month=String.Empty;
     var nodes =Model.Descendants().Where("Visible")
    .OrderBy("createDate")

    @foreach (var item in nodes)
       
    {
     //if the month changed to another month change month header
     @if(!month.Equals(item.createDate.ToString("MMMM")))
     {
           month=item.createDate.ToString("MMMM");
           @month

     }
      @item.title
      @item.description
     }
     
    }

    Change the properties accordingly.

    Thanks,

    Rajeev

  • 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