Copied to clipboard

Flag this post as spam?

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


  • Arun P K 11 posts 72 karma points
    Dec 01, 2014 @ 13:02
    Arun P K
    0

    How to sort contents based on published month and year

    Hi All,

    I am having several posts in my blog and I want to add Archive on my side bar which will be categorizing the posts based on month and year.

    I am able to fetch all the unique months with year on my sidebar but I am not able to figure out how to display my posts by sorting and grouping only selected month and year.

    Example:

    I am having the following in my sidebar right now.

     

    • November 2014 
    • October 2014 
    • September 2014 
    • August 2014 
    • July 2014 
    • June 2014
    Whenever user clicks on November 2014 I want to display all the posts which was posted on November 2014 irrespective of date and time.
    I am using macro to achieve this.
    Sidebar macro is something like this
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
       
        var blogs = Umbraco.TypedContentAtRoot().DescendantsOrSelf("ArticulateRichText").OrderBy("publishedDate desc");
        List<string> dateList = new List<string>();
        foreach (dynamic blog in blogs)
        {
    DateTime dates  = blog.GetPropertyValue<DateTime>("publishedDate");
    var month = dates.ToString("MMMM yyyy");
    dateList.Add(@month);
        }
    List<string> uniqueDateList = dateList.Distinct().ToList();
    <ul>
    @foreach(dynamic uniqueDate in uniqueDateList)
    {
    <li><a href="@uniqueDate">@uniqueDate</a></li>
    }
    </ul>
    }
    How to achieve rest of the coding or is there any inbuilt method to achieve the thing that I am looking for.
    Thanks & Regards,
    Arun P K

     

  • jivan thapa 194 posts 681 karma points
    Dec 01, 2014 @ 20:14
  • 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