首页
微语
统计
友链
留言
memos
圈子
图床
推荐
相册
网站监控
VPS监控
Search
1
Memos备忘录,记录瞬间想法
37,021 阅读
2
Jasmine - 简约、美观的博客主题
35,366 阅读
3
BearSimple - 一款简洁的Typecho主题
33,564 阅读
4
Typecho_Theme_JJ 《高仿掘金》
33,284 阅读
5
typecho评论推送插件Comment2Fanwan
32,624 阅读
手机达人
免费资源
电脑网络
娱乐休闲
网站建设
威言威语
Typecho
Emlog
WordPress
服务器
主题
插件
排行榜    
登录
/
注册
Search
标签搜索
发布
typecho
插件
教程
免费
华为
安装
PHP
图片
代码
wordpress
CSS
评论
手机
诺基亚
微信
文章
智能
微软
EMlog
Chen'mo
累计撰写
83
篇文章
累计收到
389
条评论
首页
栏目
手机达人
免费资源
电脑网络
娱乐休闲
网站建设
威言威语
Typecho
Emlog
WordPress
服务器
主题
插件
页面
微语
统计
友链
留言
memos
推荐
相册
网站监控
VPS监控
搜索到
1
篇与
的结果
2022-10-12
Typecho一些魔改代码
侧栏文章增加排列序号{collapse}{collapse-item label="侧栏文章增加排列序号" open}<?php $i = 1; ?> <?php while($post->next()): ?> <li><span class="label label-<?php echo $i; ?>"><?php echo $i; ?></span><a href="<?php $post->permalink(); ?>"><?php $post->title(); ?></a></li> <?php $i++; ?> <?php endwhile; ?>{/collapse-item}{collapse-item label="各种判断"}<?php if($this->is('index')):?> 首页 <?php if($this->is('category')):?> 分类 <?php if($this->is('category', 'category1')):?> 独立分类 <?php if($this->category == "help"): ?> 首页判断文章所在分类 <?php if($this->is('page')):?> 页面 <?php if($this->is('page', 'page1')):?> 独立页面 <?php if($this->is('post')):?> 内容页 <?php if ($pages->slug != 'page1'): ?> 导航不显示某页面 <?php if (($pages->slug != 'page1') && ($pages->slug != 'page2')): ?> 导航不显示某两个页面 <?php if ($category->slug != 'category1'): ?> 导航不显示某分类 <?php if (($category->slug != 'category1') && ($pages->slug != 'category2')): ?> 导航不显示两个分类 <?php if($this->category != "category1"): ?> 首页不显示某分类 <?php if (($this->_currentPage == 1) && ($this->sequence == 1)): ?> 首页第一篇文章 <?php elseif (array_key_exists('字段值',unserialize($this->___fields()))): ?> 自定义字段 <?php if($this->user->hasLogin()): ?> 是否登录 <?php endif; ?>{/collapse-item}{/collapse}自定义字段:<?php if (array_key_exists('image',unserialize($this->___fields()))): ?> <span class="icon-image"></span> <?php elseif (array_key_exists('music',unserialize($this->___fields()))): ?> <span class="icon-music"></span> <?php elseif (array_key_exists('play',unserialize($this->___fields()))): ?> <span class="icon-play"></span> <?php endif; ?> 首页不显示某分类<?php while($this->next()): ?> <?php if($this->category != "cateslug"): ?> //正常输出循环 <?php endif; ?> <?php endwhile; ?>调用相关文章<?php $this->related(5)->to($relatedPosts); ?> <ul> <?php while ($relatedPosts->next()): ?> <li><a href="<?php $relatedPosts->permalink(); ?>" title="<?php $relatedPosts->title(); ?>"><?php $relatedPosts->title(); ?></a></li> <?php endwhile; ?> </ul>调用指定分类文章<?php $this->widget('Widget_Archive@index', 'pageSize=6&type=category', 'mid=3') ->parse('<li><a href="{permalink}">{title}</a></li>'); ?>利用Typecho函数调用自定义分类内容显示方法在模板的functions.php文件中,加入下面的代码function themeInit($archive) { if ($archive->is('category', 'jobs')) { $archive->parameter->pageSize = 8; // 自定义条数 } }同时设定两种不同分类列表下显示不同文章输出数量的实现办法function themeInit($archive) { if ($archive->is('category', 'jobs')) { $archive->parameter->pageSize = 8; // 自定义条数 }elseif($archive->is('category', 'news')){ $archive->parameter->pageSize = 12; // 自定义条数 } }Typecho 程序如何调用循环页面、分类、标签代码方法<!--循环显示页面--> <?php $this->widget('Widget_Contents_Page_List')->to($pages); ?> <?php while($pages->next()): ?> <span class="nav-item<?php if($this->is('page', $pages->slug)): ?> nav-item-current<?php endif; ?>"> <a href="<?php $pages->permalink(); ?>" title="<?php $pages->title(); ?>"> <span><?php $pages->title(); ?></span> </a> </span> <?php endwhile; ?> <!--结束显示页面--> <!--循环所有分类--> <?php $this->widget('Widget_Metas_Category_List')->to($category); ?> <?php while ($category->next()): ?> <span class="nav-item<?php if($this->is('category', $category->slug)): ?> nav-item-current<?php endif; ?>"> <a href="<?php $category->permalink(); ?>" title="<?php $category->name(); ?>"> <span><?php $category->name(); ?></span> </a> </span> <?php endwhile; ?> <!--结束显示分类--> <!--循环显示标签 其中limit的5为显示数量--> <?php $this->widget('Widget_Metas_Tag_Cloud', array('sort' => 'count', 'ignoreZeroCount' => true, 'desc' => true, 'limit' => 5))->to($tags); ?> <?php while($tags->next()): ?> <span class="nav-item<?php if($this->is('tag', $tags->slug)): ?> nav-item-current<?php endif; ?>"> <a href="<?php $tags->permalink(); ?>" title="<?php $tags->name(); ?>"> <span><?php $tags->name(); ?></span> </a> </span> <?php endwhile; ?> <!--结束显示标签-->不同分类调用不同的模板页面<?php if($this->is('category','default')){ $this->need('default.php'); }elseif($this->is('category','technology')){ $this->need('technology.php'); }else{ $this->need('other.php'); } ?>或者<?php $slugArray = array('default','technology'); foreach($slugArray as $slug){ if($this->is('category',$slug)){ $this->need('default.php'); }else{ $this->need('other.php'); } } ?>Typecho最新24小时内文章加上NEW标签方法/** * 时间函数 * */ function timeZone($from){ $now = new Typecho_Date(Typecho_Date::gmtTime()); return $now->timeStamp - $from < 246060 ? true : false; }<?php if(timeZone($this->date->timeStamp)) echo ' new'; ?>最新文章调用<?php $this->widget('Widget_Contents_Post_Recent')->to($post); ?> <?php while($post->next()): ?> <a href=”<?php $post->permalink(); ?>” title=”<?php $post->title(); ?>”> <?php $post->title(25, '…'); ?></a> <?php endwhile; ?>热门文章调用function getHotComments($limit = 10){ $db = Typecho_Db::get(); $result = $db->fetchAll($db->select()->from('table.contents') ->where('status = ?','publish') ->where('type = ?', 'post') ->where('created <= unix_timestamp(now())', 'post') //添加这一句避免未达到时间的文章提前曝光 ->limit($limit) ->order('commentsNum', Typecho_Db::SORT_DESC) ); if($result){ foreach($result as $val){ $val = Typecho_Widget::widget('Widget_Abstract_Contents')->push($val); $post_title = htmlspecialchars($val['title']); $permalink = $val['permalink']; echo '<li><a href="'.$permalink.'" title="'.$post_title.'" target="_blank">'.$post_title.'</a></li>'; } } }大部分代码来自:https://www.itbulu.com/https://maxwuhan.com/
2022年10月12日
16,169 阅读
1 评论
1 点赞