0

我正在使用 Magento 的 AheadWorks 博客扩展,并且我的博客页面运行良好。但我希望某些类别的最新帖子的摘录出现在我的主页上。到目前为止,我已经通过添加以下内容成功设置了所有内容:

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

到“layout.xml”,添加:

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

到我主页的 phtml 文件,并通过创建“template/aw_blog/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(); ?>
4

1 回答 1

0

以下是快速解决方案:转到 aw_blog 前端模板,默认可能是这个 app/design/frontend/base/default/template/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;               
 if (array_key_exists('categories',$data = $this->getData();) && count(explode(',', $data['categories'])) == 1) {

 $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) {

谢谢!

于 2015-01-10T05:35:11.320 回答