Hello World

发现美 记录美 创造美

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

学习实践 0 评 16 °C

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; ?>
Typecho主题前台实现删除文章功能
快来做第一个评论的人吧~