fishpig $this->getPosts() 不工作

fishpig $this->getPosts() not working

我想获取我的博文的作者列表,所以我在我的 local.xml 中设置了一个块并正在尝试以下操作:

<wordpress_homepage>
    <reference name="root">
        <block type="wordpress/post_list" name="wordpress_author" template="wordpress/homepage/author/view.phtml">
            <block type="wordpress/post_list" name="wordpress_post_list" template="wordpress/post/list.phtml">
                <block type="wordpress/post_list_pager" name="wordpress_post_list_pager"/>
            </block>
        </block>
    </reference>
</wordpress_homepage>

对于我的 xml 块,但在我的 view.phtml 文件中:

<?php $posts = $this->getPosts(); ?>

returns 空。但在其他页面我可以得到这些帖子。有什么想法吗?

您提供的 XML 代码几乎显示给定作者的所有帖子(尽管不会返回任何帖子,因为在加载 homoepage 时注册表中未定义作者模型)但不起作用因为你定义的第一个块有错误的块类型(它应该是 wordpress/author_view)。

根据您的解释,您似乎真的想列出您网站上的所有作者,而不是特定作者的博客文章列表。为此,以下代码应该有所帮助:

<?php $authors = Mage::getResourceModel('wordpress/user_collection')->load() ?>
<?php if (count($authors) > 0): ?>
  <ul>
    <?php foreach($authors as $author): ?>
      <li>
        <a href="<?php echo $author->getUrl() ?>">
          <?php echo $this->escapeHtml($author->getDisplayName()) ?>
        </a>
      </li>
    <?php endforeach; ?>
  </ul>
<?php endif; ?>

此代码将加载所有用户并写出一个列表,其中包含指向每个用户页面的链接。