Blog Posts with Topics (Lister Page)
A Lister is a block of code that loads a list of records from a specific view. This code creates a Blogs Lister containing Date, Topic(s), Author(s), Primary Image (if present) and Summary (in the absence of Summary, it loads partial content of the Body). If you add this code to a page, it can be your "Blogs" page.
<!--A Lister is a block of code that loads a list of records from a specific view. --> <!--This code creates a Blogs Lister containing Date, Topic(s), Author(s), Primary Image (if present), --> <!--and Summary (in the absence of Summary, it loads partial content of the Body). --> <!--If you add this code to a page, it can be your "Blogs" page.--> <!--This code block creates a Blog Posts lister page showing author(s) info (if present) and topics under title, right column loads topics for filtering.--> @section head { <style> .media-metadata { margin-bottom: 30px; } .media-metadata .topics > span:not(:last-child):after { content: " | "; } </style> } <div class="row"> <div class="col-sm-3 order-sm-2"> @BRT.CategoryList(tableId:"Content", viewId:"BlogPosts", fieldId:"Topic", template: @<div class="topic-list-wrap"> <h4 class="topic-list">Topics</h4> <p><a href="/blogs">All</a></p> @foreach(EngineRecord c in item) { <p><a href="/blogs?topic=@c["Id"]">@c["Label"]</a></p> } </div>) </div> <div class="col-sm-9"> @BRT.Lister(tableId: "Content", viewId: "BlogPosts", fields: new[] {"Title","PubDate","Summary","Body","Topic","Link","PrimaryImage", "Authors.PreferredName","Authors.FirstName","Authors.MiddleName","Authors.LastName","Authors.NameSuffix","Authors.PrimaryImage"}, condition: (String.IsNullOrEmpty(Request.QueryString["topic"])?null:ConditionMeta.Parse("[Topic.Id]='" + Request.QueryString["topic"] + "'")), template: @<div> @foreach(EngineRecord record in item) { <article class="media"> @if(!record.IsDBNull("PrimaryImage") && record.GetFiles("PrimaryImage").Count > 0) { if(record.GetFiles("PrimaryImage")[0].ContentType.StartsWith("image/")) { if(!record.IsDBNull("Link")) { <a href="@record["Link"]" target="_blank"> <img src="@(record.GetFiles("PrimaryImage")[0].Url)?width=120&height=120&mode=crop" class="mr-3 img-fluid" alt="@(String.IsNullOrEmpty(record.GetFiles("PrimaryImage")[0].Title) ? record.GetFiles("PrimaryImage")[0].Filename : record.GetFiles("PrimaryImage")[0].Title)"/> </a> } else { <a href="/post/@record.Href"> <img src="@(record.GetFiles("PrimaryImage")[0].Url)?width=120&height=120&mode=crop" class="mr-3 img-fluid" alt="@(String.IsNullOrEmpty(record.GetFiles("PrimaryImage")[0].Title) ? record.GetFiles("PrimaryImage")[0].Filename : record.GetFiles("PrimaryImage")[0].Title)"/> </a> } } } <div class="media-body"> <h5 class="mt-0 mb-0"> <a href="/post/@record.Href"> @if(!record.IsDBNull("Title")) { @record["Title"] } </a> </h5> <small class="media-metadata text-muted"> @if(!record.IsDBNull("PubDate")) { <span>@record.GetDateTime("PubDate").ToShortDateString()</span> } @if(!record.IsDBNull("Authors") && record.GetRecordList("Authors").Count > 0) { if(!record.IsDBNull("PubDate")){ <span> - </span> } <span>by: </span> <span class="topics"> @foreach(EngineRecord record_authors in record.GetRecordList("Authors")) { <span> <a href="/author/@record_authors.Href"> @if(!record_authors.IsDBNull("PreferredName")) { <span>@record_authors["PreferredName"]</span> } else { <span>@record_authors["FirstName"]</span> } @if(!record_authors.IsDBNull("MiddleName")) { <span>@record_authors["MiddleName"]</span> } @if(!record_authors.IsDBNull("LastName")) { <span>@record_authors["LastName"]</span> } @if(!record_authors.IsDBNull("NameSuffix")) { <span>@record_authors["NameSuffix"]</span> } </a> </span> } </span> } @if (!record.IsDBNull("Topic") && record.GetCategory("Topic").Count > 0) { if(!record.IsDBNull("Authors") || !record.IsDBNull("PubDate")){ <span> - </span> } <span class="topics"> @foreach(CategoryFieldItem topic in record.GetCategory("Topic")) { <span>@topic.Label</span> } </span> } </small> @if(!record.IsDBNull("Summary")) { <p>@BRT.Raw(@record.GetString("Summary").Summarize(250))</p> } else { <p>@BRT.Raw(@record.GetString("Body").Summarize(250))</p> } </div> </article> } </div>) </div> </div>