Umbraco Slider Editor Issue

I set up my solution with the umbraco starer kit. It has a slider editor that is controling the blogs on a page. After I had lot of blogs imported, the sliderworks OK except that I can’t control the order of the displayed blogs. The pages are showing oldest to newest, but I need the blogs to be reversed. So I added a new blog and it goes to the bottom under the blogs document type in back office. This blog has a newer date that the ones I imported. Interestingly enough this newly created blog is still on the last page. I tried moving blogs around with sort children and then I added the publish date to the blogs collection and sorted by publish date. That didn’t fix anything. See screenshots. I certianly can re-import everything descending, but my concern is as soon as someone adds a new blog it will still show up on the last page. Any help would be greatly appreciated.

Blog Posts Slider Display

Sort Children

Sort Collection By Publish Date

First Page

Last Page

Hi Paul,

You don’t say what version you’re using - looks like v16.

Just looked in a v13 start kit - you need to amend the macro partial that renders these to change to the sort order. I think it’s the same in v16 - will have a look for a quick setup to check.

Look in Views\MacroPartials\LatestBlogPosts.cshtml

Line 37

    var blogposts = startNode.Children.OrderBy(x => x.CreateDate).ToList();

Change to

    var blogposts = startNode.Children.OrderByDescending(x => x.SortOrder).ToList();

For v16 I think you can just change (can’t test this).

Views\Components\LatestBlogPosts\Default.cshtml

Line 6

@foreach (IPublishedContent post in Model.BlogPosts)

To

@foreach (IPublishedContent post in Model.BlogPosts.OrderByDescending(x => x.SortOrder))

Once you’re at a point of starting to customise like this it’s probably time to learn partials and write your own.

Thanks Steve, I have v16. But it doesn’t matter that much. What you’re saying works for sorting each page. However, the order of all pages are still reversed. At that point you’re talking about it’s passing in the number of blogs selected with the slider. What I can’t seem to find is where the code is pulling all the blogs. If I could then I would change the sort order at that point in the code.

On views/partials/b;ockgrid/components/latestblogposts.cshtml:

@await Component.InvokeAsync(“LatestBlogPosts”,
new { numberOfPosts = Model.Content.NumberOfPosts, startNodeKey = Model.Content.StartNode?.Key ?? Guid.Empty })

This is where it passes the number of posts from the slider to the page.

Hi Paul,

Confession time - I’ve never used the sample site :wink: But it looks like from V16 the code you’re looking for isn’t actually installed by the package - it’s just present in a dll - this is not much help for you!

The ViewComponent code can be seen here though:

As you’re looking to amend and customise what I’d suggest you do is copy this but rename it. Create your own View Component based on this so you can amend and make perfect as you wish.

Here’s the documentation for it:

HTH

Steve

Sounds good Steve! I really appreaciate your help! I’ll give it a shot, but it looks like it could work. I’ll let you know if I have further questions.

Just got it working with the custom view component. Yea!

1 Like

Great work! If you can mark that as the solution it helps the forum.