博主

7小时前在线

MAO486
一个宅的新“家”
博主 MAO486
博主 7小时前 在线自豪地使用 Typecho 建站搭配使用 🌻Sunny 主题当前在线 15 人
歌曲封面 未知作品

网站已运行 193 天 15 小时 57 分

Powered by Typecho & Sunny

15 online · 89 ms

Title

笔记

某昴

·

📦杂

·

Article

计划报废,我爬

在让Ai帮我写typecho主题,搜集了一些我可能需要用到的代码

index输出header.php、footer.php
左边是标题、发布时间、分类、标签、评论(数量)
右边是带缩略图的文章列表,参考自定义某分类并输出缩略图

♾️ php 代码:
<?php $this->widget('Widget_Archive@index', 'pageSize=4&type=category', 'mid=23')->to($indexpub); ?>
<?php while($indexpub->next()): ?>
    <?php $indexpub->permalink(); ?>
    <?php $indexpub->title() ?>
    <?php Fimg_Plugin::showfimg($indexpub->cid,4);?>
    <?php $indexpub->excerpt(80, '……'); ?>
<?php endwhile; ?>

首页不显示某分类

♾️ php 代码:
<?php while($this->next()): ?>
<?php if($this->category != "cateslug"): ?>
//正常输出循环
<?php endif; ?>
<?php endwhile; ?>

标签页面:全部标签列表 - 按时间排序

♾️ php 代码:
<?php $this->widget('Widget_Metas_Tag_Cloud')
                ->to($taglist); ?><?php while($taglist->next()): ?>
<li><a href="<?php $taglist->permalink(); ?>" title="<?php $taglist->name(); ?>"><?php $taglist->name(); ?></a></li>
<?php endwhile; ?>

归档页面:全部文章列表

♾️ php 代码:
<?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=10000')->parse('<li>{year}-{month}-{day} : <a href="{permalink}">{title}</a></li>'); ?>

上一篇与下一篇调用代码

♾️ php 代码:
<?php $this->thePrev(); ?> <?php $this->theNext(); ?>

调用自定义分类最新文章

♾️ php 代码:
<?php $this->widget('Widget_Archive@index', 'pageSize=6&type=category', 'mid=47')
->parse('<li><a href="{permalink}">{title}</a></li>'); ?>

文章日期格式化

♾️ php 代码:
//文章发表时间格式化
function time_ago($date) {
    $timestamp = strtotime($date->format('Y-m-d H:i:s'));
    $current_time = time();
    $time_diff = $current_time - $timestamp;

    if ($time_diff < 60) {
        return $time_diff . "秒前";
    } elseif ($time_diff < 3600) {
        return floor($time_diff / 60) . "分钟前";
    } elseif ($time_diff < 86400) {
        return floor($time_diff / 3600) . "小时前";
    } elseif ($time_diff < 2592000) { // 30天以内
        return floor($time_diff / 86400) . "天前";
    } elseif ($time_diff < 31536000) { // 1年内
        return floor($time_diff / 2592000) . "个月前";
    } elseif ($time_diff < 94608000) { // 3年内
        return floor($time_diff / 31536000) . "年前";
    } else {
        return $date->format('Y/m/d'); // 超过3年显示具体日期
    }
}
♾️ php 代码:
<?php echo time_ago($this->date); ?>

文章字数统计

♾️ php 代码:
function  art_count ($cid){
$db=Typecho_Db::get ();
$rs=$db->fetchRow ($db->select ('table.contents.text')->from ('table.contents')->where ('table.contents.cid=?',$cid)->order ('table.contents.cid',Typecho_Db::SORT_ASC)->limit (1));
echo mb_strlen($rs['text'], 'UTF-8');
}
♾️ php 代码:
<?php echo art_count($this->cid); ?>
现在已有 27 次阅读,0 条评论,0 人点赞
Comment:共0条
发表
搜 索 消 息 足 迹
你还不曾留言过..
你还不曾留下足迹..
博主 不再显示
博主