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
In Umbraco 8 we had some code to create pagination. In Umbraco 9 (Cloud) it doesn't seem to work.
Anyone some ideas?
@{ int pageSize = 1; IEnumerable<IPublishedContent> nodes = Umbraco.Content(Guid.Parse("5b8c723b-0b8b-44ef-80f4-9e4402afe54d")).ChildrenOfType("nieuwsItem").Where(x => x.IsVisible() && x.Value<DateTime>("datum") <= DateTime.Now.Date && x.Value<DateTime>("datum") != null).OrderByDescending(x => x.Value<DateTime>("datum")); int totalNodes = nodes.Count(); int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize); var page = 1; int.TryParse(Request.QueryString["page"], out page); if (page > totalPages){ page = totalPages; }else if (page < 1){ page = 1; }} @foreach (var item in nodes.Skip((page - 1) * pageSize).Take(pageSize)){ <a href="@item.Url()" title="@item.Name()">@item.Name()</a> } @if (totalNodes > pageSize){ <ul class="pagination"> @if (page > 1){ <li><a href="?page=@(page-1)">Prev</a></li> } @for (int p = 1; p < totalPages + 1; p++){ string selected = (p == page) ? "selected" : String.Empty; <li class="@selected"><a href="?page=@p" title="Go to page @p">@p</a></li> } @if (page < totalPages){ <li><a href="?page=@(page+1)">Next</a></li> } </ul> }
Hi Peter,
Hope that you are doing good. I have been trying to find a solution for you for the last couple of days.
And today I got it to work with the following code
First add the following lines below the using statements in your template
@inject Microsoft.AspNetCore.Http.IHttpContextAccessor HttpContextAccessor
Then use the follow to make the create pagination in Umbraco 9
@{ int pageSize = 5; var nodes = Umbraco.Content(Guid.Parse("ec4aafcc-0c25-4f25-a8fe-705bfae1d324")) .Children() .Where(x => x.IsVisible()); int totalNodes = nodes.Count(); int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize); int page = 1; Int32.TryParse(HttpContextAccessor.HttpContext.Request.Query["page"], out page); if (page > totalPages){ page = totalPages; }else if (page < 1){ page = 1; } } <ul> @foreach (var item in nodes.Skip((page - 1) * pageSize).Take(pageSize)) { <li> <a href="@item.Url()">@item.Name()</a> </li> } </ul> @if (totalNodes > pageSize){ <ul class="pagination"> @if (page > 1){ <li><a href="?page=@(page-1)">Prev</a></li> } @for (int p = 1; p < totalPages + 1; p++){ string selected = (p == page) ? "selected" : String.Empty; <li class="@selected"><a href="?page=@p" title="Go to page @p">@p</a></li> } @if (page < totalPages){ <li><a href="?page=@(page+1)">Next</a></li> } </ul> }
Give it a go and remember to make changes so it matches your set up.
I am looking forward to hearing from you if you can make it work too
Best
/Dennis
Dennis, you're the man! Thanks a lot! Works like a charm.
Hi Peter
Great to hear that it works like a charm for you
Please help me I am new to Umbraco Cloud Please help me how to do the the changes to the above template to get pagination may i have to create it as Macro or Partial ?
I got the answer it works well thanks
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Creating pagination in Umbraco Cloud (V9.3.0)
In Umbraco 8 we had some code to create pagination. In Umbraco 9 (Cloud) it doesn't seem to work.
Anyone some ideas?
Hi Peter,
Hope that you are doing good. I have been trying to find a solution for you for the last couple of days.
And today I got it to work with the following code
First add the following lines below the using statements in your template
Then use the follow to make the create pagination in Umbraco 9
Give it a go and remember to make changes so it matches your set up.
I am looking forward to hearing from you if you can make it work too
Best
/Dennis
Dennis, you're the man! Thanks a lot! Works like a charm.
Hi Peter
Great to hear that it works like a charm for you
/Dennis
Please help me I am new to Umbraco Cloud Please help me how to do the the changes to the above template to get pagination may i have to create it as Macro or Partial ?
I got the answer it works well thanks
is working on a reply...