typecho按标签获取相关文章设置

发布于 / 随记 / 0条评论 / Tags: typecho / 8 次浏览

typecho做博客还是很好用的,为了seo,需要获取相关文章,如下:

  1. Archive.php 里面有函数:默认按标签获取相关

    //type支持传author和不传,不传代表按标签推荐相关

     public function related($limit = 5, $type = NULL)
     {
         $type = strtolower($type);
     
         switch ($type) {
             case 'author':
                 /** 如果访问权限被设置为禁止,则tag会被置为空 */
                 return $this->widget('Widget_Contents_Related_Author',
                 array('cid' => $this->cid, 'type' => $this->type, 'author' => $this->author->uid, 'limit' => $limit));
             default:
                 /** 如果访问权限被设置为禁止,则tag会被置为空 */
                 return $this->widget('Widget_Contents_Related',
                 array('cid' => $this->cid, 'type' => $this->type, 'tags' => $this->tags, 'limit' => $limit));
         }
     }
    

2.所以代码如下

<?php $this->related(5)->to($relatedPosts); ?>
    <ul>
        <?php while ($relatedPosts->next()): ?>
        <li><a href="<?php $relatedPosts->permalink(); ?>" title="<?php $relatedPosts->title(); ?>"><?php $relatedPosts->title(); ?></a></li>
        <?php endwhile; ?>
    </ul>




    评论区(暂无评论)