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
Please, i want to know how i can add a pagination to this code:
@{ @* -- Setup a counter variable for position -- *@ var position = 1; } @* -- List children pages from the current page (aka Model) -- *@ @foreach (var page in @Model.Children.Where("umbracoNaviHide != true")) { <div class="noticia"> <div class="n-left"> <img src="@page.foto" width="137" height="103" alt="xp" /> </div> <div class="n-right"> <h2>@page.Name</h2> <p><strong> @page.fecha.ToString("dd-MM-yyyy") </strong></p> @{ var texto = @page.texto.ToString(); var textoNoHtml = umbraco.library.StripHtml(texto); var textoTrunc = umbraco.library.TruncateString(textoNoHtml, 200, "..."); } <p> @textoTrunc </p> <div class="read-more2"><a href="@page.Url">leer mรกs...</a></div> </div> <img src="images/not-divider.png" alt="divider" class="divider2"/> </div> @* -- After every 3rd item insert a <br/> -- *@ if (position % 3 == 0) { } @* -- Increase the position counter by 1 -- *@ position++; }This code works well but i'd like to show 5 items per page with a next and previous button and a list of links to each page.
How could i do it?
Thanks for the answer.
Hi Nelson,
Try this below code, I added your code with paging code. I hope it work for you.
----------------------------------
@using umbraco.MacroEngines@inherits umbraco.MacroEngines.DynamicNodeContext@{ var pagesToList = @Model.Children..Where("umbracoNaviHide != true"); // configuration var itemsPerPage = String.IsNullOrEmpty(Parameter.ItemsPerPage) ? 5 : int.Parse(Parameter.ItemsPerPage); var previousLabel = String.IsNullOrEmpty(Parameter.PreviousLabel) ? "Previous" : Parameter.PreviousLabel; var nextLabel = String.IsNullOrEmpty(Parameter.NextLabel) ? "Next" : Parameter.NextLabel; // paging calculations var numberOfItems = pagesToList.Count(); int currentPage = 1; if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage)) { currentPage = 1; } currentPage--; var numberOfPages = numberOfItems % itemsPerPage == 0 ? Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) : Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) + 1; foreach (var item in pagesToList.Skip(currentPage * itemsPerPage).Take(itemsPerPage)) { <div class="noticia"> <div class="n-left"> <img src="@page.foto" width="137" height="103" alt="xp" /> </div> <div class="n-right"> <h2>@page.Name</h2> <p><strong> @page.fecha.ToString("dd-MM-yyyy") </strong></p> @{ var texto = @page.texto.ToString(); var textoNoHtml = umbraco.library.StripHtml(texto); var textoTrunc = umbraco.library.TruncateString(textoNoHtml, 200, "..."); } <div class="usedcarpager"> <p class="pagingPages"> @{ // Google style paging links if (currentPage > 0) { <a href="?page=@(currentPage)">« @previousLabel</a> } else { <span class="pagingDisabled">« @previousLabel</span> } var Pages = Enumerable.Range(1, (int)numberOfPages); foreach (var number in Pages) { if (number - 1 != currentPage) { <a href="?page=@number">@number</a> } else { @number } @Html.Raw("  "); } if (currentPage < Pages.Count() - 1) { <a href="?page=@(currentPage + 2)">@nextLabel »</a> } else { <span class="pagingDisabled">@nextLabel »</span> } } </p> </div> }
Thanks, i'll try to use itlater, then i'll tell you if it works.
Jazz, thank you so much, i solved my problem with that code.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
hi, i have a question about a news list
Please, i want to know how i can add a pagination to this code:
@{
@* -- Setup a counter variable for position -- *@
var position = 1;
}
@* -- List children pages from the current page (aka Model) -- *@
@foreach (var page in @Model.Children.Where("umbracoNaviHide != true"))
{
<div class="noticia">
<div class="n-left">
<img src="@page.foto" width="137" height="103" alt="xp" />
</div>
<div class="n-right">
<h2>@page.Name</h2>
<p><strong>
@page.fecha.ToString("dd-MM-yyyy")
</strong></p>
@{
var texto = @page.texto.ToString();
var textoNoHtml = umbraco.library.StripHtml(texto);
var textoTrunc = umbraco.library.TruncateString(textoNoHtml, 200, "...");
}
<p>
@textoTrunc
</p>
<div class="read-more2"><a href="@page.Url">leer mรกs...</a></div>
</div>
<img src="images/not-divider.png" alt="divider" class="divider2"/>
</div>
@* -- After every 3rd item insert a <br/> -- *@
if (position % 3 == 0)
{
}
@* -- Increase the position counter by 1 -- *@
position++;
}
This code works well but i'd like to show 5 items per page with a next and previous button and a list of links to each page.
How could i do it?
Thanks for the answer.
Hi Nelson,
Try this below code, I added your code with paging code. I hope it work for you.
----------------------------------
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var pagesToList = @Model.Children..Where("umbracoNaviHide != true");
// configuration
var itemsPerPage = String.IsNullOrEmpty(Parameter.ItemsPerPage) ? 5 : int.Parse(Parameter.ItemsPerPage);
var previousLabel = String.IsNullOrEmpty(Parameter.PreviousLabel) ? "Previous" : Parameter.PreviousLabel;
var nextLabel = String.IsNullOrEmpty(Parameter.NextLabel) ? "Next" : Parameter.NextLabel;
// paging calculations
var numberOfItems = pagesToList.Count();
int currentPage = 1;
if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage))
{
currentPage = 1;
}
currentPage--;
var numberOfPages = numberOfItems % itemsPerPage == 0 ? Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) : Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) + 1;
foreach (var item in pagesToList.Skip(currentPage * itemsPerPage).Take(itemsPerPage))
{
<div class="noticia">
<div class="n-left">
<img src="@page.foto" width="137" height="103" alt="xp" />
</div>
<div class="n-right">
<h2>@page.Name</h2>
<p><strong>
@page.fecha.ToString("dd-MM-yyyy")
</strong></p>
@{
var texto = @page.texto.ToString();
var textoNoHtml = umbraco.library.StripHtml(texto);
var textoTrunc = umbraco.library.TruncateString(textoNoHtml, 200, "...");
}
<div class="usedcarpager">
<p class="pagingPages">
@{
// Google style paging links
if (currentPage > 0)
{
<a href="?page=@(currentPage)">« @previousLabel</a>
}
else
{
<span class="pagingDisabled">« @previousLabel</span>
}
var Pages = Enumerable.Range(1, (int)numberOfPages);
foreach (var number in Pages)
{
if (number - 1 != currentPage)
{
<a href="?page=@number">@number</a>
}
else
{
@number
}
@Html.Raw("  ");
}
if (currentPage < Pages.Count() - 1)
{
<a href="?page=@(currentPage + 2)">@nextLabel »</a>
}
else
{
<span class="pagingDisabled">@nextLabel »</span>
}
}
</p>
</div>
}
Thanks, i'll try to use it
later, then i'll tell you if it works.
Jazz, thank you so much, i solved my problem with that code.
is working on a reply...