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.
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:
@inherits UmbracoViewPage
@{
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))
@functions {
//gets the page from the querystring and sets it to one if it is out of range
int SetPageNumber(int pageCount)
{
var page = 1;
if (!string.IsNullOrEmpty(Request.QueryString["page"]))
{
int.TryParse(Request.QueryString["page"], out page);
if (page <= 0 || page > pageCount)
{
page = 1;
}
}
return page;
}
}
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?
BlogListSection.cshtml
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
// 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();
}
@SectionHelper.RenderSectionStart(Model.BackgroundColor.Label)
@Html.Partial($"~/Views/Partials/Nested/Component/TitleComponent.cshtml", new TitleComponent(Model))
@foreach (var blogItem in blogs)
{
blogItem.ItemsPerRow = itemsPerRow;
Blogpost Order by Last published
Hi everyone
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?
thank you Luis
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:
If you have models for your posts (eg.
BlogPost
) then you can do:Hope that gives you enough to get there...
Hi Dan
Thanks for your help :) Later i will check this and keep you informed if results.
br Luis
Hello Dan
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:
@inherits UmbracoViewPage
@{ Layout = "master.cshtml";
}
@Html.Partial("~/Views/Partials/SectionHeader.cshtml", new HeaderSection(Model))
@Html.Partial("~/Views/Partials/Renderers/RenderSections.cshtml", Model.NestedContentBefore)
@if (!blogItems.HasValue()) {
There are no posts at this time, try again later.
@if (pagedBlogposts.Count > 0) { @SectionHelper.RenderSectionStart(Model.BackgroundColor?.Label, true)
} @Html.Partial("~/Views/Partials/Renderers/RenderSections.cshtml", Model.NestedContentAfter)
@functions { //gets the page from the querystring and sets it to one if it is out of range int SetPageNumber(int pageCount) { var page = 1; if (!string.IsNullOrEmpty(Request.QueryString["page"])) { int.TryParse(Request.QueryString["page"], out page); if (page <= 0 || page > pageCount) { page = 1; } } return page; } }
and this for Home template:
@using Umbraco.Web.PublishedModels @inherits Umbraco.Web.Mvc.UmbracoViewPage
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.
Hi Dan
As you say i was searching on partial and i found this template, maybe its here...what you think?
BlogListSection.cshtml
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{ // 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(); }
@SectionHelper.RenderSectionStart(Model.BackgroundColor.Label) @Html.Partial($"~/Views/Partials/Nested/Component/TitleComponent.cshtml", new TitleComponent(Model))
@foreach (var blogItem in blogs) { blogItem.ItemsPerRow = itemsPerRow;
Hi Luis,
Could be! If so, you probably need to add an order by to the line that gets the blogs. Something like:
Does that help?
Hi Dan
Yes! Helps :) Thank you..five stars!!
Luis
is working on a reply...