I managed to add pagination to the Umbraco news feed within the TXT Site Template using the following code (hope this helps a lot of people in itself who I have seen around the forum!)
Now I want to add a filter-by-category on the news feed for the end user to distill posts dependant on area of interest by either a dropdown or checkbox. I'm trying to keep it simple at the backend and base it on a category data type (from a drop down list) which can be selected by the editor prior to publishing the post. Like with the last question i'm stuck in the mud and trawling through god knows how many posts. If I can incorporate code into the above then even better!
Adding Pagination to TXT Newsfeed
Hi,
I managed to add pagination to the Umbraco news feed within the TXT Site Template using the following code (hope this helps a lot of people in itself who I have seen around the forum!)
@inherits UmbracoTemplatePage
@{
Layout = "umbLayout.cshtml";
var pageSize = 2;
if(Model.Content.HasValue("numberOfItemsPerPage")){
pageSize = Model.Content.GetPropertyValue<int>("numberOfItemsPerPage");
}
var page = 1; int.TryParse(Request.QueryString["page"], out page);
// If the editor has not explicitly provided the "Page title" property page
// then just show the name of the page otherwise show the provided title
var pageTitle = string.IsNullOrWhiteSpace(CurrentPage.Title)
? CurrentPage.Name
: CurrentPage.Title;
var homePage = CurrentPage.AncestorsOrSelf(1).First();
var newsOverview = homePage.umbNewsOverviews.First();
var items = newsOverview.umbNewsItems;
var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);
if (page > totalPages)
{
page = totalPages;
}
else if (page < 1)
{
page = 1;
}
}
<!-- Main -->
<div id="main-wrapper">
<div id="main" class="container">
<div class="row">
<div class="12u skel-cell-mainContent">
<input type='hidden' id='current_page' />
<input type='hidden' id='show_per_page' />
<div id='content' class="content">
<!-- Content -->
<header>
<h2>@pageTitle</h2>
</header>
@foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize))
{
var title = string.IsNullOrWhiteSpace(item.Title)
? item.Name
: item.Title;
var dateTime = item.PublishDate == default(DateTime)
? item.CreateDate
: item.PublishDate;
<section>
<h3><a href="@item.Url">@title</a></h3>
<span class="byline">@item.SubHeader</span>
<ul class="meta">
<li class="timestamp">@dateTime.ToString("f")</li>
</ul>
@if (string.IsNullOrWhiteSpace(item.Image) == false)
{
<a href="@item.Url" class="image image-full"><img src="@item.Image" alt="" /></a>
}
@Umbraco.Truncate(item.BodyText, 200)
<a href="@item.Url" class="button">Continue Reading</a>
</section>
}
<div class="pagination">
<ul>
@if (page > 1)
{
<li><a href="?page=@(page-1)">Prev</a></li>
}
@for (int p = 1; p < totalPages + 1; p++)
{
<li class="@(p == page ? "active" : string.Empty)">
<a href="?page=@p">@p</a>
</li>
}
@if (page < totalPages)
{
<li><a href="?page=@(page+1)">Next</a></li>
}
</ul>
</div>
</div>
<!-- /Content -->
</div>
<div id='page_navigation'></div>
</div>
</div>
</div>
<!-- /Main -->
Now I want to add a filter-by-category on the news feed for the end user to distill posts dependant on area of interest by either a dropdown or checkbox. I'm trying to keep it simple at the backend and base it on a category data type (from a drop down list) which can be selected by the editor prior to publishing the post. Like with the last question i'm stuck in the mud and trawling through god knows how many posts. If I can incorporate code into the above then even better!
Hi Christopher,
So you can't find out how to use DropDownDataType for categorising ?
Thanks
is working on a reply...