magento中获得博客aw_blog插件的分类与最近文章

magento中获得博客aw_blog插件的分类与最近文章
magento中获得博客aw_blog插件的分类与最近文章

magento的博客插件AW_Blog,此插件是个不错的magento博客插件,官网页面在:http://www.magentocommerce.com/magento-connect/aheadworks/extension/1516/blog-extension-by-aheadworks

此magento博客插件就是小巧灵活,可以发个博文,支持用户评论。对于有人力物力的magento网站来说,我倒是希望将博客媒体等内容与magento分离出来。如果是个人的网站此aw_blog博客插件也是一个选择。

在magento中使用此插件也不是一般的magento使用者可以胜任的,同样要具备一定的magento开发开发知识,不然还是用不好的。因为插件不一定可以融入你的模板设计中,或者插件的内容没有显示在你想要显示的位置,这都是要手动去改代码的。本文来讲下如何将AW Blog插件的分类与最近文章显示在首页。

1.在你的magento后台 CMS -> Pages ->home (也就是进入你的CMS首页编辑页面)在左侧的标签中选择 conten,添加如下XML

<reference name="content">
 <block type="core/template" name="blog_home" template="aw_blog/bloghome.phtml" />
</reference>


2.在你的magento模板文件中,找到Aw Blog的模板文件夹,我的在app/design/frontend/default/default/template/aw_blog ,你的可能有所不同,在里面新建文件bloghome.phtml写入如下代码(代码未优化)

<?php
$collection = Mage::getModel('blog/cat')->getCollection()
		->addStoreFilter(Mage::app()->getStore()->getId())
		->setOrder('sort_order ', 'asc');

		$route = Mage::helper('blog')->getRoute();

		foreach ($collection as $item)
		{
			$item->setAddress($this->getUrl($route . "/cat/" . $item->getIdentifier()));
		}

?>
<div class="home-blog">

	<div class="blog-right">
		<h2><?php echo $this->__('Last News');?></h2>
			<div class="last-posts">
			<?
			  $blogPosts = Mage::getModel('blog/blog')->getCollection()
								->addStoreFilter(Mage::app()->getStore()->getId())
								->setOrder('created_time', 'desc');
					$blogPosts->getSelect()->limit(2);
					$blog_content = "";
					echo '<ul>';
					foreach($blogPosts as $post){
					   echo '<li><a class="post-title" rel="nofollow" href="blog/'.$post->getData('identifier').'">'.$post->getData('title').'</a>';
					   echo  '<div class="post-short">'.$post->getShortContent().'<a rel="nofollow" href="blog/'.$post->getData('identifier').'">Read more</a></div>';
					   echo   '</li>';
					}
					echo '</ul>';
			?>
			</div>
	</div>

	<div class="blog-left">
		<div class="blog-catalog">
			<?php if($collection): ?>
				<div class="menu-categories">
					<h2><?php echo $this->__('Blog Categories');?></h2>
					<ul>
						<?php $cats = $collection; ?>
						<?php foreach ($cats as $cat): ?>
								<li><a href="<?php echo $cat->getAddress(); ?>" ><?php echo $cat->getTitle();?></a></li>
						<?php endforeach; ?>
					</ul>
				</div>
			<?php endif;?>
		</div>
	</div>
</div>

刷新首页,就可以看到如文章上面显示的图的内容了,css改下,代码优化下就可以了。此bloghome.phtml文件中的内容可以放在任意模板文件中。请大家自己选择使用。$blogPosts->getSelect()->limit(2);为显示的文章数量。

注:本例使用magento1.5  Aw Blog版本1.0.21  其它版本可能略有不同。 Aw Blog后台添加分类时Identifier勿留空格,按照url规范书写。

参考文章:http://passion4code.com/2010/09/25/magento-aw-blog-widget/

转载表明出处:www.hellokeykey.com

《magento中获得博客aw_blog插件的分类与最近文章》有9个想法

评论已关闭。