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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?