Created
March 29, 2017 14:10
-
-
Save amirkhan81/365766425b41b7f6cb50dff20f914912 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage | |
@using umbraco.cms.businesslogic.Tags | |
@{ | |
@* grab your selection of content line normal *@ | |
@* set the page size and check for the query string "page" *@ | |
var pageSize =10; | |
var page =1;int.TryParse(Request.QueryString["page"],out page); | |
var totalPages =(int)Math.Ceiling((double)selection.Count()/(double)pageSize); | |
if(page > totalPages) | |
{ | |
page = totalPages; | |
} | |
else if (page < 1) | |
{ | |
page =1; | |
} | |
@* end pagination *@ | |
} | |
@if (selection.Any()) | |
{ | |
@* render posts here *@ | |
} | |
@{ | |
@* draw pagination nav *@ | |
if (totalPages > 1){ | |
var previousPageIsEllipsis = true; | |
<nav class="pager"> | |
<ul> | |
@if (page > 1) | |
{ | |
<li><a href="?page=@(page-1)">< Prev</a></li> | |
} | |
@for (int p = 1; p < totalPages + 1; p++) | |
{ | |
var linkClass = (p == page) ? "disabled" : "active"; | |
if (p == page){ | |
<li class="@Html.Raw(linkClass)"><a href="?page=@p">@p</a></li> | |
previousPageIsEllipsis = false; | |
}else{ | |
if( p == 1 | |
|| p == page - 1 | |
|| p == page + 1 | |
|| p == totalPages - 1 | |
|| p == totalPages){ | |
<li class="@Html.Raw(linkClass)"><a href="?page=@p">@p</a></li> | |
previousPageIsEllipsis = false; | |
}else{ | |
if (previousPageIsEllipsis){ | |
continue; | |
}else{ | |
<li class="ellipsis">...</li> | |
previousPageIsEllipsis = true; | |
} | |
} | |
} | |
} | |
@if (page < totalPages) | |
{ | |
<li><a href="?page=@(page+1)">Next ></a></li> | |
} | |
</ul> | |
</nav> | |
} | |
@* end nav *@ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment