Skip to content

Instantly share code, notes, and snippets.

@ps-team
Created October 27, 2017 09:51
Show Gist options
  • Select an option

  • Save ps-team/98d27717b3de555430f7afc50848acd7 to your computer and use it in GitHub Desktop.

Select an option

Save ps-team/98d27717b3de555430f7afc50848acd7 to your computer and use it in GitHub Desktop.
News list with category filtering Requires meta data for categories to be added to the page so editors can control categories shown.
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
@{
// Get category value from url to filter results with
var catFilter = Request.QueryString["TaxonomyKey"];
// Get news articles
var newsArticlesQuery = Query.Where("SC_T_ID").IsEqualTo("-2875009").And("Property_TaxonomyCategories").Contains(catFilter).OrderBy("Property_DatePublished").Descending;
var newsArticles = new NodeFinder().Find(newsArticlesQuery, selectCount:8);
//Get array of categories from the meta data checklist
var catNodes = CurrentNode.Data.NewsCatList.Values();
//Set initial active class on 'all' link
var allActive = "inactive";
if (catFilter == null) {
allActive = "active";
}
}
<div id="filteredNewsList">
<h2 class="usr-headingLargeCentred">Latest</h2>
<div class="centerFloat">
<ul class="filterNav">
<li class="@allActive"><a href="?TaxonomyKey&amp;#filteredNewsList">All</a></li>
@foreach (var childNode in catNodes)
{
var catNode = CurrentContext.Taxonomy.GetByPath("StructuredContent/newscategories/" + childNode);
var activeCat = "inactive";
if (catFilter == catNode.Key) {
activeCat = "active";
}
<li class="@activeCat"><a href="[email protected]&amp;#filteredNewsList">@childNode</a></li>
}
</ul>
</div>
<div class="blockWrapper blockWrapperSpaced2 newsBlocks">
@for (var i = 0; i < newsArticles.Count; i += 4)
{
<div class="blockRow">
@foreach (var newsArticle in newsArticles.Skip(i).Take(4))
{
var publishedDate = newsArticle.Data.DatePublished.ToString("d MMMM yyyy");
var description = newsArticle.Data.Description.ToString();
var charCount = description.Length;
var ellipsis = "";
var desc2 = description;
if(charCount >= 80) {
ellipsis = "&hellip;";
desc2 = description.Substring(0, 80) + ellipsis;
}
<a class="block TextBlockArticle" href="@newsArticle.Path">
<div class="block-content TextBlockArticle-content">
<span class="TextBlockArticle-date">@publishedDate</span>
<h3 class="block-title TextBlockArticle-title">@newsArticle.Title</h3>
<p>@Html.Raw(desc2)</p>
</div>
</a>
}
</div>
}
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment