Search code examples
phpwordpressmagentofishpig

fishpig $this->getPosts() not working


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?


Solution

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