1

我想为我的博客文章获取作者列表,所以我在我的 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(); ?>

返回空值。但在其他页面我可以得到帖子。有任何想法吗?

4

1 回答 1

0

您提供的 XML 代码几乎显示了给定作者的所有帖子(尽管在加载同源页面时不会返回任何帖子,因为 Author 模型未在注册表中定义)但不会工作,因为您定义的第一个块有错误块类型(应该是 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; ?>

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

于 2015-03-07T09:15:42.833 回答