Forum Discussion

jjeremiah's avatar
jjeremiah
Expert
7 years ago

List blog posts from parent node

I have a community structure:

 

Category
        - Category Blog

        SubCat 1
        SubCat 2
        SubCat 3

 

Is there a simple way to add a component to the SubCats, that will list the latest blog posts from the Category Blog?

 

Thanks

 

 

 

 

  • You can use API v2 to write a custom component to achieve that.
  • jjeremiah  I think OOTB component shows the latest post of their own and their nested child categories/boards but not from the parent or siblings. But you can go with a custom component approach to get it done.

    • jjeremiah : Did you check this Document.  Hope it will work.

       

      If my post is helpful and answers your question, please give "Kudos" and "Accept it as a Solution."

      Thanks & Regards,
      Abhishek Illindra

  • You can use API v2 to write a custom component to achieve that.
    • jjeremiah's avatar
      jjeremiah
      Expert

      It always helps me to see the working code... when it's done...here's how I've implemented this custom component - which lists the 5 most recent blog posts.

      notes:

      1. The query is where the target blog is identified.... so the code is reusable in a different component with minimal changes.

      2. I've included the class model/structure in the bottom half, so that the component will pick up the CSS styling rules for our community.

       

      <#-- Blog teaser   v4-->
      <#-- change the "board.id" in the query to focus on a different blog/board  -->
      <#include "message-macros"/>
      <#assign qry = "SELECT id, view_href, author.id, author.view_href, author.login, subject, teaser, body, post_time, post_time_friendly, conversation.style,  board.id, board.title, board.view_href, current_revision.last_edit_time FROM messages WHERE conversation.style = 'blog' AND board.id='sws-22'ORDER BY post_time DESC LIMIT 5" />
      <#assign messages = executeLiQLQuery(qry) />
      <#if messages?size gt 0>
      
      <#assign brd = messages[0] />
      <div class="lia-panel lia-panel-standard  custom-component-blogteaser">
      	<div class="lia-decoration-border">
      		<div class="lia-decoration-border-top">
      			<div class="lia-decoration-border-content">
      				<div class="lia-panel-heading-bar-wrapper">
      					<div class= "lia-panel-heading-bar">
      						<div class= "lia-panel-heading-bar-title">
      							<h1> Recent blogs from:  &nbsp<a href="${getFieldValue(brd.board.view_href)}"> ${getFieldValue(brd.board.title)} </a> </h1>
      							<hr /> 
      						</div>
      						<div class = "lia-panel-content-wrapper">
      							<div class="lia-panel-content">
      								<#list messages as msg>
      								<a href="${getFieldValue(msg.view_href)}" target="_top">
      							         <h3 style='display:inline'>-  ${getFieldValue(msg.subject)}  </h3></a>  <p style='display:inline'> &nbsp;&nbsp; By:   ${getFieldValue(msg.author.login)}</p>
      								 	<hr /> 
      								 </#list>
      							</div>
      						</div>
      					</div>
      				</div>
      			</div>
      		</div>
      	</div>
      </div>
      </#if>

       

      Hope this helps someone else.

       

      John