使用Magento的AheadWorks博客扩展显示特定类别的帖子

问题描述:

我正在使用Magento的AheadWorks博客扩展,并且我的博客页面工作正常。但我想从我的主页上看到我的某些类别的最新帖子的摘录。我加入已经成功地建立一切迄今:使用Magento的AheadWorks博客扩展显示特定类别的帖子

<block type="blog/blog" name="blog.latest" template="aw_blog/blog-home.phtml" /> 

为 “layout.xml”,加入:

<?php echo $this->getChildHtml('blog.latest') ?> 

到我的主页的PHTML文件,并通过创建“模板/ aw_blog /博客-home.phtml”。

问题是,我无法弄清楚如何限制显示的类别。例如,您会在我的“blog-home.phtml”文件中看到我试图将帖子限制在“新闻”类别。我已经尝试了其他论坛的很多解决方案,但无论我做什么,我都会看到来自各个类别的帖子。有谁知道我需要添加/删除我的代码来限制类别吗?

<?php $posts = $this->getPosts("news"); ?> 
<div id="messages_product_view"> 
    <?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?> 
    <?php echo Mage::app()->getLayout()->getMessagesBlock()->getGroupedHtml(); ?> 
</div> 

<?php $numberOfPosts = 1 ?> 
<?php $renderedPosts = 0 ?> 
<?php foreach ($posts as $post): ?> 
    <div class="postWrapper"> 
     <div class="postTitle"> 
      <h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2> 
     </div> 
     <div class="postContent"><?php echo $post->getPostContent(); ?></div> 
     <?php echo $this->getBookmarkHtml($post) ?> 
     <div class="tags"><?php echo $this->getTagsHtml($post) ?></div> 
     <div class="postDetails"> 
      <?php if ($this->getCommentsEnabled()): ?> 
       <?php echo $post->getCommentCount(); ?> <a href="<?php echo $post->getAddress(); ?>#commentBox" >Comments</a> | 
      <?php endif; ?> 
      <?php $postCats = $post->getCats(); ?> 
           <?php echo "<h1>" . $postCats[2] . "</h1>"; ?> 
      <?php if (!empty($postCats)): ?> 
       <?php echo Mage::helper('blog')->__('Posted in'); ?> 
       <?php foreach ($postCats as $data): ?> 
        <a href="<?php echo $data['url']; ?>"><?php echo $data['title']; ?></a> 
       <?php endforeach; ?> 
      <?php else: ?> 
      <?php endif; ?></div> 
      <?php $renderedPosts ++ ?> 
      <?php if ($renderedPosts = $numberOfPosts) { 
       break; 
      } 
      ?> 
    </div> 
<?php endforeach; ?> 
<?php //$this->getPages(); ?> 
+0

您应该通过电子邮件向他们的支持发送邮件的链接。 AW非常棒,恕我直言。您可以遍历返回的内容,看看是否有方法可以在本地过滤结果? –

+0

嗯,这将工作,除了Magento的AW博客扩展程序是免费的,他们的技术支持仅用于支付客户。不过,我会尝试他们的论坛。 – americanknight

+0

Heheh,好吗?如果不是,那么购买他们的优秀扩展之一,并寻求帮助。顺便说一句,他们只是帮助解决了他们之间和另一个供应商的扩展之间的冲突。问题不在AW的代码中,但他们给了我们修复。他们是一个伟大的供应商。 –

以下是快速的解决方案: 转到aw_blog前端模板,默认情况下可能是这个应用程序/设计/前端/基/默认/模板/ aw_blog/menu.phtml 检查更换:

if ($posts = $this->getRecent(): 

$currentBlogCat = Mage::getSingleton('blog/cat'); 

if ($posts = $this->getRecent($currentBlogCat['cat_id'])): 

现在打开/app/code/community/AW/Blog/Block/Menu/Sidebar.php 检查以下功能:

public function getRecent() 

添加参数吧:

public function getRecent($currentCat=false) 

而且,与

$collection = clone self::$_collection; 
$data = $this->getData(); 
if($currentCat>0)$data['categories']=$currentCat; 
# Category fix # 
if (array_key_exists('categories',$data) && count(explode(',', $data['categories'])) == 1) { 

感谢替换下面的代码块

$collection = clone self::$_collection;    
if (array_key_exists('categories',$data = $this->getData();) && count(explode(',', $data['categories'])) == 1) {