Typecho的author.php文件打造用户中心社区的参数调用和使用方法

typecho的author.php文件

是用户页面,但是官网给予的参考文档很少,很多人也是直接忽略掉了这个页面

我也是通过打印$this

获取了我们大概能调用,有用的东西

例如:获取当前用户的信息

$userInfo = (object)$this->pageRow;
print_r($userInfo->screenName);

具体可调用参数,可打印print_r($userInfo)来查看

输出该作者的文章,这里跟列表页面一样的

至于为什么?

archive.php 通用(分类、搜索、标签、作者)页面文件

可以看结构,这四个页面能调用的东西都大致相同

<?php if ($this->have()): ?>
  <?php while($this->next()): ?>
  内容
  <?php endwhile; ?>
<?php else: ?>
    <article class="article-post">
        <div class="content-null">
            <p>空空如也~</p>
        </div>
    </article>
<?php endif; ?>

输出这个人的评论

需要在functions.php添加代码

/*输出作者发表的评论*/
class Widget_Post_AuthorComment extends Widget_Abstract_Comments
{
    var $getAuthorUid;
    
    public function execute()
    {
        global $AuthorCommentId;//全局作者id
        $select  = $this->select()->limit($this->parameter->pageSize)
        ->where('table.comments.status = ?', 'approved')
        ->where('table.comments.authorId = ?',$this->parameter->authorId)//获取作者id
        ->where('table.comments.type = ?', 'comment')
        ->order('table.comments.coid', Typecho_Db::SORT_DESC);//根据coid排序
        $this->db->fetchAll($select, array($this, 'push'));
    }
}

然后再author.php可以调用

<?php $this->widget('Widget_Post_AuthorComment@author','pageSize=8&authorId=用户id')->to($AuthorComment); ?>
<?php if ($AuthorComment->have()): ?>
    <?php while($AuthorComment->next()): ?>
    
    //循环处
    //可调用参数
    //$AuthorComment->permalink(); 该评论所属文章链接
    //$AuthorComment->title();该评论所属文章标题
    //$AuthorComment->content();该评论内容
    //$AuthorComment->dateWord();该评论时间
    
    
    <?php endwhile; ?>
    <?php else: ?>    
    <div class="text-center"><div class="icon-svg svg-empty"></div><div class="text-muted">看起来这里没有任何东西。</div></div>    
    <?php endif; ?>

尚待补充…

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索