我正在使用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(); ?>
答案 0 :(得分: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) {
谢谢!