Forum
Blog post list in a Block
Hi,
I'm not sure how (if) this can be done.
I have a section on a page that includes a query of resent blog posts. I want to create a block for this instead. So is there a way to include the query on a HTML template which the block is created from. The block will allow the user to add some content normally but also needs to list the latest blog post of which does not require the users input.
Here is my original code
<div class="container">
<div class="row">
<div class="col-md-8 pad-right">
<?php perch_content_custom('Page Content', array(
'template' => 'home/welcome.html',
)); ?>
</div>
<div class="col-md-4">
<div class="section-header">
<h2>Latest News</h2>
</div>
<ul class="blog-articles-list list-unstyled">
<?php
perch_blog_custom(array(
'count' => 2,
'category' => array('news'),
'template' => 'home_list.html',
'sort'=>'postDateTime',
'sort-order'=>'DESC',
));
?>
</ul>
<?php perch_content_custom('Page Content', array(
'template' => 'home/banners.html',
)); ?>
</div>
</div>
</div>
From this I instead created a block replacing the perch_content_custom template calls with the actual HTML, but as you can see I still have the perch_blog_custom array trying to get the blog posts. Blocks are HTML templates so I'm not sure how to use this function to show posts in a block.
<perch:block type="block26" label="Block: Welcome">
<div id="block26">
<div class="container">
<div class="row">
<div class="col-md-8 pad-right">
<div class="section-header">
<h2><perch:content id="header" type="text" /></h2>
</div>
<div class="left_image">
<img class="img-responsive" src="<perch:content id="image" type="image" />" alt="">
</div>
<p><perch:content id="text" type="textarea" /></p>
</div>
<div class="col-md-4">
<div class="section-header">
<h2>Latest News</h2>
</div>
<ul class="blog-articles-list list-unstyled">
<?php
perch_blog_custom(array(
'count' => 2,
'category' => array('news'),
'template' => 'home_list.html',
'sort'=>'postDateTime',
'sort-order'=>'DESC',
));
?>
</ul>
<div id="banner-membership">
<a href="<perch:if exists="bannerLinkPage"><perch:content id="bannerLinkPage" type="pagelist" /></perch:if><perch:if exists="bannerLinkUrl"><perch:content id="bannerLinkUrl" type="text" /></perch:if>">
<div class="media">
<div class="media-left">
<span class="fa-stack fa-lg fa-3x">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-users fa-stack-1x fa-inverse"></i>
</span>
</div>
<div class="media-body">
<h3><perch:content id="bannerMembershipTitle" type="text" /> <span class="only">only</span> <span class="money"><perch:content id="bannerMembershipPrice" type="text"/></span></h3>
</div>
</div>
</a>
</div>
<div id="banner-box-tops">
<a href="<perch:if exists="bannerBoxTopsLinkPage"><perch:content id="bannerBoxTopsLinkPage" type="pagelist" /></perch:if><perch:if exists="bannerBoxTopsLinkUrl"><perch:content id="bannerBoxTopsLinkUrl" type="text" /></perch:if>">
<div class="media">
<div class="media-left">
<img class="img-responsive" src="<perch:content id="bannerBoxTopsImage" type="image" />" alt="">
</div>
<div class="media-body">
<h3><perch:content id="bannerBoxTopsTitle" type="text" /></h3>
<p><perch:content id="bannerBoxTopsSubTitle" type="text" /></p>
</div>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
</perch:block>
Hope this make since...
Thanks.
You could build a field type to do that, but I'm not aware of one already existing.