1
votes

I am unable to fetch post tags added from wordpress admin panel. I am using fishpig magento extension and everything is working perfectly.

I am fetching posts using the code

$posts = $this->getPosts();

and I need tags associated with each post.

Please help.

1

1 Answers

3
votes

You can get the tags for an individual post by calling the getTags method on the post object. Here is a snippet pertaining to post tags from the post view template:

<?php $tags = $post->getTags() ?>
<?php if (count($tags) > 0): ?>
    <span><?php echo (count($categories) == 0) ? $this->__('This post was tagged with') : $this->__('and was tagged with') ?> </span> 
    <?php $it = count($tags) ?>
    <?php foreach($tags as $tag): ?>
        <a href="<?php echo $tag->getUrl() ?>">
            <?php echo $tag->getName() ?>
        </a><?php if (--$it > 0): ?>, <?php endif; ?>
    <?php endforeach; ?>
<?php endif; ?>

You have a collection of posts rather than a single post, you can call getTags on an individual post as you are iterating over your collection.

foreach($posts as $post) {
    $tags = $post->getTags();
}