Copied to clipboard

Flag this post as spam?

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


  • Mohamed Besher El Said 39 posts 258 karma points
    May 15, 2015 @ 19:24
    Mohamed Besher  El Said
    0

    News Archive

    I want to create news archive in umbraco website like this img 

  • Carl Jackson 139 posts 478 karma points
    May 22, 2015 @ 18:20
    Carl Jackson
    0

    You are likely going to need to do it with a render controller and custom model.

    To get you started :

    Model

    public class NewsListingModel : IPublishedContent
    {
        public IEnumerable<string> Categories { get; set;  }
    
        public IEnumerable<YearArchive> Years { get; set; }
    
        public class YearArchive
        {
            public int Year { get; set; }
    
            public IEnumerable<int> Months { get; set; }
        }
    }
    

    Controller

    public class NewsListingController : RenderMvcController
    {
        public ActionResult NewsListing(BlogListingModel model)
        {
    
            model.Years = model.Content.Children.Select(x => x.CreateDate).GroupBy(d => d.Year).Select(y => y.FirstOrDefault()).Select(y =>
                new NewsListingModel.YearArchive
                {
                    Year = y.Year,
                    Months = model.Content.Children.Where(
                    x => x.CreateDate.Year == y.Year).Select(
                        x => x.CreateDate.Month
                        ).GroupBy(mg => mg).Select(m=>m.FirstOrDefault())
                });
    
            return CurrentTemplate(model);
        }
    }
    

    You could then then making an archive content type which takes a int month and int year parameter to a controller to filter the children of the node you are after?

    Or you could extend the model further so it all happens on the same page?

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft