Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have a page with some articles (blogposts) and when i publish one i would like have this post as last published and visible at first of the last ones.
What happen is, every articles/blog post i published they go to the last.
Its possible inverse this order?
What code do you have to get them currently, as this will require modifying?
In general terms you'll need to write a query that appends OrderByDescending for the date property on the end to reverse the order.
For instance, this would work:
Model.Children().OrderByDescending(p => p.CreateDate)
If you have models for your posts (eg. BlogPost) then you can do:
Model.Children<BlogPost>().OrderByDescending(p => p.CreateDate)
Hope that gives you enough to get there...
Thanks for your help :)
Later i will check this and keep you informed if results.
Sorry taking your time again.
Your suggestion really fix my issue in my blogposts pages.
But i notice the 3 blogposts i have on frontpage (index) didn't change the order.
I have open the Home template and see if there is any code to change but not, redirect to master.chtml and there also didn't find.
You know how i can make the last post could be visible also on frontpage?
This is the code for Blog template:
Layout = "master.cshtml";
var blogItems = Model.Children.Select(x => new Blogpost(x)).OrderByDescending(p => p.CreateDate).ToList();;
var hasPaging = true;
var numberOfPosts = (int)Model.ItemsToShow;
var pageCount = (int)Math.Ceiling((double)blogItems.Count / (double)numberOfPosts);
var page = SetPageNumber(pageCount);
var pagedBlogposts = blogItems.Skip((page - 1) * numberOfPosts).Take(numberOfPosts).ToList();
@Html.Partial("~/Views/Partials/SectionHeader.cshtml", new HeaderSection(Model))
There are no posts at this time, try again later.
@if (pagedBlogposts.Count > 0)
foreach (var blogPost in pagedBlogposts)
<div class="column @RazorHelper.ColumnClass(Model.ItemsPerRow?.ToString())">
if (blogItems.Count > numberOfPosts && hasPaging)
<div class="column is-12">
<div class="buttons is-centered">
@for (int i = 1; i <= pageCount; i++)
<a class="button is-medium @(page == i ? "is-light" : "is-link")" href="@("?page=" + i)">@i</a>
//gets the page from the querystring and sets it to one if it is out of range
int SetPageNumber(int pageCount)
var page = 1;
int.TryParse(Request.QueryString["page"], out page);
if (page <= 0 || page > pageCount)
page = 1;
and this for Home template:
Hi! I'm finding it quite tricky to read the contents. Is there definitely no specific code on the home page, maybe in a partial, for there? It sounds like you need to locate this code first.
As you say i was searching on partial and i found this template, maybe its here...what you think?
// get the list of blogs
var blogsNode = new Blog(Model.Blog);
var blogs = blogsNode.Children.Select(x => new Blogpost(x)).Take((int)Model.ItemsToShow);
var itemsPerRow = Model.ItemsPerRow?.ToString();
@Html.Partial($"~/Views/Partials/Nested/Component/TitleComponent.cshtml", new TitleComponent(Model))
@foreach (var blogItem in blogs)
blogItem.ItemsPerRow = itemsPerRow;
Could be! If so, you probably need to add an order by to the line that gets the blogs. Something like:
var blogs = blogsNode.Children.Select(x => new Blogpost(x)).OrderByDescending(p => p.CreateDate).Take((int)Model.ItemsToShow);
Does that help?
Yes! Helps :)
Thank you..five stars!!
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted