2015-03-31 124 views

回答

3

您可以通過在帖子對象上調用getTags方法來獲取單個帖子的標籤。下面是關於從後視圖模板張貼標籤的一個片段:

<?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(); 
} 
+0

謝謝!標籤即將到來。 – Kajal 2015-04-01 05:02:43

+0

有沒有任何功能可以在fishpig中獲取相關帖子? – Kajal 2015-04-01 05:22:40

+0

真棒解決方案 – Jalpesh 2018-02-22 15:23:28

相關問題