Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save prjseal/85613cb05bea0d62e2fdc4515b46c1d1 to your computer and use it in GitHub Desktop.
Save prjseal/85613cb05bea0d62e2fdc4515b46c1d1 to your computer and use it in GitHub Desktop.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using System.Linq
@{
var blogPostList = Model.Content.Parent;
IEnumerable<dynamic> allPosts = blogPostList.Children.Where("Visible");
List<int> ids = allPosts.Select(x => (int)x.Id).ToList();
int indexOfThisPost = ids.IndexOf(Model.Content.Id);
bool isLast = (indexOfThisPost >= ids.Count() - 1);
bool isFirst = indexOfThisPost == 0;
string olderUrl = "";
string newerUrl = "";
string olderName = "";
string newerName = "";
<div class="row clearfix" style="margin-bottom:2em;">
@if(!isFirst)
{
var olderPage = Umbraco.Content(ids[indexOfThisPost - 1]);
olderUrl = olderPage.Url;
olderName = olderPage.Name;
<div class="col-xs-6">
<a title="@olderName" class="btn btn-primary readmore" href="@olderUrl"><i class="fa fa-angle-left"></i> Previous Post</a>
</div>
}
@if(!isLast)
{
var newerPage = Umbraco.Content(ids[indexOfThisPost + 1]);
newerUrl = newerPage.Url;
newerName = newerPage.Name;
<div class="col-xs-6">
<a title="@newerName" style="float:right;" class="btn btn-primary readmore" href="@newerUrl">Next Post <i class="fa fa-angle-right"></i></a>
</div>
}
</div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment