我无法获取从 wordpress 管理面板添加的帖子标签。我正在使用 fishpig magento 扩展,一切正常。
我正在使用代码获取帖子
$posts = $this->getPosts();
我需要与每个帖子关联的标签。
请帮忙。
我无法获取从 wordpress 管理面板添加的帖子标签。我正在使用 fishpig magento 扩展,一切正常。
我正在使用代码获取帖子
$posts = $this->getPosts();
我需要与每个帖子关联的标签。
请帮忙。
getTags
您可以通过调用post 对象上的方法来获取单个帖子的标签。这是与帖子视图模板中的帖子标签有关的片段:
<?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; ?>
您有一个帖子集合而不是单个帖子,您可以getTags
在迭代您的集合时调用单个帖子。
foreach($posts as $post) {
$tags = $post->getTags();
}