doumen1883 2015-03-06 19:48
浏览 35
已采纳

fishpig $ this-> getPosts()无效

I want to get a list of authors for my blog posts, so I set up a block in my local.xml and am trying the following:

<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>

for my xml block but in my view.phtml file:

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

returns null. But in other pages I can get the posts. Any ideas?

  • 写回答

1条回答 默认 最新

  • duanan2732 2015-03-07 09:15
    关注

    The XML code you have given almost displays all posts for a given author (although no posts will be returned as an Author model is not defined in the registry when loading the homoepage) but won't work as the first block you define has the wrong block type (it should be wordpress/author_view).

    Based on your explanation, it seems like you actually want to list all of the authors on your site rather than a list of blog posts by a specific author. To do this, the following code should help:

    <?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; ?>
    

    This code will load all users and write out a list with links to each users page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 eclipse连接sap后代码跑出来空白
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案