Comments (9)
文章目录
functions.php
function createCatalog($obj) {
global $catalog;
global $catalog_count;
$catalog = array();
$catalog_count = 0;
$obj = preg_replace_callback('/<h([1-6])(.*?)>(.*?)<\/h\1>/i', function($obj) {
global $catalog;
global $catalog_count;
$catalog_count ++;
$catalog[] = array('text' => trim(strip_tags($obj[3])), 'depth' => $obj[1], 'count' => $catalog_count);
return '<h'.$obj[1].$obj[2].'><a name="cl-'.$catalog_count.'"></a>'.$obj[3].'</h'.$obj[1].'>';
}, $obj);
return $obj;
}
function getCatalog() {
global $catalog;
$index = '';
if ($catalog) {
$index = '<ul>'."\n";
$prev_depth = '';
$to_depth = 0;
foreach($catalog as $catalog_item) {
$catalog_depth = $catalog_item['depth'];
if ($prev_depth) {
if ($catalog_depth == $prev_depth) {
$index .= '</li>'."\n";
} elseif ($catalog_depth > $prev_depth) {
$to_depth++;
$index .= '<ul>'."\n";
} else {
$to_depth2 = ($to_depth > ($prev_depth - $catalog_depth)) ? ($prev_depth - $catalog_depth) : $to_depth;
if ($to_depth2) {
for ($i=0; $i<$to_depth2; $i++) {
$index .= '</li>'."\n".'</ul>'."\n";
$to_depth--;
}
}
$index .= '</li>';
}
}
$index .= '<li><a href="#cl-'.$catalog_item['count'].'">'.$catalog_item['text'].'</a>';
$prev_depth = $catalog_item['depth'];
}
for ($i=0; $i<=$to_depth; $i++) {
$index .= '</li>'."\n".'</ul>'."\n";
}
$index = '<div id="toc-container">'."\n".'<div id="toc">'."\n".'<strong>文章目录</strong>'."\n".$index.'</div>'."\n".'</div>'."\n";
}
echo $index;
}
把上面的代码放到主题文件functions.php内,然后在functions.php内搜索关键词function themeInit,如果有themeInit这个函数,则在themeInit这个函数内添加下面的代码
有themeInit函数
if ($archive->is('single')) {
$archive->content = createCatalog($archive->content);
}
无themeInit函数
function themeInit($archive) {
if ($archive->is('single')) {
$archive->content = createCatalog($archive->content);
}
}
调用代码
<?php getCatalog(); ?>
from theme.
倒计时代码
<Script Language="JavaScript">
var timedate= new Date("May 2,2010");
var times= "唐涛的生日";
var now = new Date();
var date = timedate.getTime() - now.getTime();
var time = Math.floor(date / (1000 * 60 * 60 * 24));
if (time >= 0)
document.write( "现在离"+times+"还有: "+time +"天")
</Script>
from theme.
文章归档页面
<?php
/**
* 文章存档
*
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('header.php'); ?>
<div class="col-md-12 text-center">
<div class="page-header">
<h2 class="page-title"><?php $this->title() ?></h2>
<hr>
</div>
</div>
<div class="col-md-12">
<article class="page-wrapper" itemscope itemtype="http://schema.org/BlogPosting">
<div class="post-content" itemprop="articleBody">
<?php
$stat = Typecho_Widget::widget('Widget_Stat');
Typecho_Widget::widget('Widget_Contents_Post_Recent', 'pageSize='.$stat->publishedPostsNum)->to($archives);
$year=0; $mon=0; $i=0; $j=0;
$output = '<div class="archives">';
while($archives->next()){
$year_tmp = date('Y',$archives->created);
$mon_tmp = date('m',$archives->created);
$y=$year; $m=$mon;
if ($year > $year_tmp || $mon > $mon_tmp) {
$output .= '</ul></div>';
}
if ($year != $year_tmp || $mon != $mon_tmp) {
$year = $year_tmp;
$mon = $mon_tmp;
$output .= '<div class="archives-item"><h4>'.date('Y年m月',$archives->created).'</h4><hr><ul class="archives_list">'; //输出年份
}
$output .= '<li>'.date('d日',$archives->created).' <a href="'.$archives->permalink .'">'. $archives->title .'</a></li>'; //输出文章
}
$output .= '</ul></div></div>';
echo $output;
?>
</div>
</article>
</div><!-- end #main-->
<?php $this->need('footer.php'); ?>
from theme.
运行时间代码
functions.php
// 设置时区
date_default_timezone_set('Asia/Shanghai');
/**
* 秒转时间,格式 年 月 日 时 分 秒
*
*/
function getBuildTime() {
// 在下面按格式输入本站创建的时间
$site_create_time = strtotime('2019-12-20 20:00:00');
$time = time() - $site_create_time;
if (is_numeric($time)) {
$value = array(
"years" => 0, "days" => 0, "hours" => 0,
"minutes" => 0, "seconds" => 0,
);
if ($time >= 31556926) {
$value["years"] = floor($time / 31556926);
$time = ($time % 31556926);
}
if ($time >= 86400) {
$value["days"] = floor($time / 86400);
$time = ($time % 86400);
}
if ($time >= 3600) {
$value["hours"] = floor($time / 3600);
$time = ($time % 3600);
}
if ($time >= 60) {
$value["minutes"] = floor($time / 60);
$time = ($time % 60);
}
$value["seconds"] = floor($time);
echo '<span class="btime">'.$value['years'].
'年'.$value['days'].
'天'.$value['hours'].
'小时'.$value['minutes'].
'分</span>';
} else {
echo '';
}
}
调用代码
<?php getBuildTime(); ?>
from theme.
时间轴代码
style.css
/* 站点动态时间轴 */
#teamnewslist ol{list-style:none;margin-left: 36px;padding-left: 14px;border-left: 2px solid
#eee;font-size: 18px;color: #666;}
#teamnewslist b{font-size: 12px;font-weight: normal;color: #999;display: block;position: relative;margin-bottom:5px;}
#teamnewslist b::after{position: absolute;top: 6px;left: -22px;content: '';width: 14px;height: 14px;border-radius: 50%;background-color: #fff;border: 2px solid #ccc;box-shadow: 2px 2px 0 rgba(255,255,255,1), -2px -2px 0 rgba(255,255,255,1)}
#teamnewslist li{list-style:none;margin: 0 0 20px 0;line-height: 100%;}
#teamnewslist li:hover{color: #555;}
#teamnewslist li:hover b::after{border-color: #C01E22;}
#teamnewslist li:hover b{color: #C01E22;}
调用代码
!!!
<h4>
<span style="font-size: 20px; color: #99ccff;">
<a style="color: #99ccff;text-decoration: none;">2019年</a>
</span>
</h4>
<div id="teamnewslist">
<ol>
<li><b>2019年10月</b>遭受大规模攻击,导致进入小黑屋三天。收录被K</li>
<li><b>2019年7月</b>修复DUX模板大部分BUG</li>
<li><b>2019年06月</b>完成jinjun.top的域名备案</li>
<li><b>2019年03月</b>腾讯云服务器过期,启用jinjun.top域名</li>
<li><b>2019年01月</b>完成对jinjun.top域名的收购</li>
</ol>
</div>
!!!
from theme.
编辑页面/编辑文章
编辑页面代码
<?php if($this->user->hasLogin()):?>
<a href="<?php $this->options->adminUrl(); ?>write-page.php?cid=<?php echo $this->cid;?>">编辑</a>
<?php endif;?>
编辑文章代码
<?php if($this->user->hasLogin()):?>
<a href="<?php $this->options->adminUrl(); ?>write-post.php?cid=<?php echo $this->cid;?>">编辑</a>
<?php endif;?>
from theme.
直达评论区代码
<li itemprop="interactionCount">
<a itemprop="discussionUrl" href="<?php $this->permalink() ?>#comments">
<?php $this->commentsNum('评论', '1 条评论', '%d 条评论'); ?></a>
</li>
from theme.
显示摘要内容
<?php $this->excerpt(); ?>
显示全文内容
<?php $this->content(); ?>
抄了post.php的……不然图片也太大了
<div class="post-content" itemprop="articleBody">
<?php $this->content(); ?>
</div>
from theme.
自适应css
在index.php的PHP代码前直接插入即可
<style>
/* 在这里添加你的自定义CSS样式 */
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
.container {
width: 100%;
margin: 0 auto;
}
.content {
}
</style>
from theme.
Related Issues (3)
- default-typecho
- book-typecho HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from theme.