Display blog posts to CMS pages :
In app/design/frontend/default/default/template/aw_blog/
Step 1:
Create a new file home_latest_blog.phtml with the following code:
<?php $posts = Mage::getModel('blog/blog') ->getCollection() ->addPresentFilter() ->addStoreFilter(Mage::app()->getStore()->getId()) ->addFieldToFilter('status', 1) ->setOrder('created_time ', 'desc') ->setPageSize(3); if(count($posts)): ?> <h3><?php echo $this->__('BLOG-Latest Posts');?></h3> <ul> <?php foreach ($posts as $post): ?> <li> <div class="postContent std"><?php echo $this->helper('cms')->getBlockTemplateProcessor()->filter($post->getShortContent()); ?></div> <a href="<?php echo $this->getBaseUrl().'blog/'.$post->getIdentifier(); ?>"><?php echo $post->getTitle(); ?></a> (<?php echo $this->formatDate($post->getCreatedTime(), Mage::getStoreConfig('blog/blog/dateformat'), true); ?>) </li> <?php endforeach; ?> </ul> <div id="messages_product_view"></div> <?php endif;?>
If You want to change blog post limit Change in ->setPageSize(3) set your size
Step 2:
Now call home_latest_blog.phtml in cms page Open your cms page -> Edit page -> Click Content tab
And add this
{{block type="core/template" name="homepage.blog" template="aw_blog/home_latest_blog.phtml"}}
and if you want call in any other phtml file:
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('aw_blog/home_latest_blog.phtml')->toHtml(); ?>
1 Comment
mahender · July 5, 2016 at 3:04 pm
I implemented this it’s working fine but when i select a blog post it redirecting to Respected blog detail page but the blog post containes imges in middle of the content those images not showing, only alt text is showing, the path of the image is also changing.