Home → News, Reviews and Tutorials → Magento → Magento – AheadWorks Blog – Add blog posts to CMS pages
For further details about Website Design
E: info@h22solutions.co.uk
T: 07899 842 073
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | class AW_Blog_Block_Blog extends Mage_Core_Block_Template { public function getPosts($catfilter) { $tag = $this->getRequest()->getParam('tag'); if(!$catfilter) { $collection = Mage::getModel('blog/blog') ->getCollection() ->addPresentFilter() ->addStoreFilter(Mage::app()->getStore()->getId()) ->setOrder('created_time ', 'desc'); } else { $collection = Mage::getModel('blog/blog') ->getCollection() ->addPresentFilter() ->addStoreFilter(Mage::app()->getStore()->getId()) ->setOrder('created_time ', 'desc') ->addCatFilter($catfilter); } |
1 2 3 4 5 | $posts = $this->getPosts(3); // 3 is the blog category id $limit=4; $i=0; foreach ($posts as $post): if ($i++ > $limit) break; |
1 | {{block type="blog/blog" name="blog" alias="list_blog" template="aw_blog/blog-cmspagename.phtml"}} |
Published by Terry Ellis in Magento, Web Design.
pradeep
hi,
i need blog serach and archive with date and post count !! can you please help how to implement that 2 thing in aheadwroks blog module
Edgard Niza
Very useful tutorial, bookmarked !
Thanks
Terry Ellis
Thank you
Terrie Mrazek
I blog often and I truly appreciate your information. This great article has truly peaked my interest. I’m going to bookmark your website and keep checking for new information about once a week. I subscribed to your RSS feed too.
Marquerite Senst
May I simply say what a comfort to discover somebody who really knows what they are discussing online. You actually understand how to bring an issue to light and make it important. A lot more people ought to check this out and understand this side of the story. I was surprised that you’re not more popular since you certainly possess the gift.
Kevin
Thanks for the tutorial… this has limited my main blog page to just display posts from the first category… how can I get the main blog page to display all categories?
Terry Ellis
Hi Kevin,
Try removing ->addCatFilter($catfilter);
See if that helps.
Kevin
Hi Terry, thanks for your help… this displays all the categories on the main blog page now but also on the individual cms pages where I want specific categories.
Terry Ellis
Hi Kevin, I dont have a test site ‘live’ at the moment to test this, but try this…
In step 1 (above),
please update your code to the above (updated code).
In step 2,
try changing getPosts(3); to getPosts($_GET["catfil"]);
In step 3,
on the individual cms pages, where you need a filter, try changing template=”aw_blog/blog-cmspagename.phtml” to template=”aw_blog/blog-cmspagename.phtml?catfil=3“
Kevin
Hi Terry, unfortunately it’s still displaying all categories.
Also ‘;’ is missing from the end of the following line in step 1:
->setOrder(‘created_time ‘, ‘desc’)
Terry Ellis
Thanks Kevin, semi colon added back in.
Try this,
In step 3, revert back to original code (as above) and then add inline catfil=”3″ (or other cat id). Or don’t add this to display all categories.
In Step 2, replace
$posts = $this->getPosts(3);
with something like
$catfil = $this->getData(‘catfil’);
$posts = $this->getPosts($catfil);