【教程】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; ?>

尚待补充...

来源:https://wiki.owoii.com/archives/27.html

文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/1230
2 条评论
1.8k

发表评论

已有 2 条评论

  1.     Win 10 /    Chrome
    2022-11-12 13:26

    给哥哥

  2. 牛魔王     Win 7 /    Chrome
    2022-10-30 11:32

    :乖::乖:

!