计划报废,我爬
在让Ai帮我写typecho主题,搜集了一些我可能需要用到的代码
index输出header.php、footer.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); ?>