Skip to content

Instantly share code, notes, and snippets.

@ps-team
Created October 27, 2017 09:50
Show Gist options
  • Save ps-team/71cdb3468d8f85214cc54f6d2314a990 to your computer and use it in GitHub Desktop.
Save ps-team/71cdb3468d8f85214cc54f6d2314a990 to your computer and use it in GitHub Desktop.
Generate a **distinct** list of 'categories' assigned to a set of nodes. This code loops through a set of nodes, creates an array from the categories on each node, then we get only the distinct ones. This array can then be looped through again to build a list of your categories.
@using Contensis.Framework.Web.Search;
@{
var query = Query.Where("Property_Path").StartsWith("/connect/blog/").And("Property_AuthorID").IsEqualTo(authorId.ToString()).OrderBy("Property_Title");
var nodes = new NodeFinder().Find(query, selectCount: 20);
string fulltagslist = "";
}
@foreach(var node in nodes)
{
fulltagslist += node.Data.BlogCategories + ",";
}
@{
string[] myfulltagslist = fulltagslist.Split(',');
myfulltagslist = myfulltagslist.Distinct().ToArray();
}
<ul class="sys_tagcloud-control">
@if(myfulltagslist.Length != 1){
foreach (string tag in myfulltagslist)
{
if (tag != "")
{
<li class="sys_tagcloud-tag"><a href="/Connect/blog/blog-archive.aspx?category=@tag">@tag</a> </li>
}
}
} else {
<li class="sys_tagcloud-tag">There are no categories available. </li>
}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment