|
|
5 J" r4 ?+ N3 K, f1 ?
可以将 SpeciaTheme 中 Heropress Pro 主题转换成 Typecho 主题,下面是具体的实现过程:
. Q( Q& l6 J! w2 z, m3 B' }+ `7 Z
8 o& l7 ^2 F* D$ l1.下载主题文件
3 K2 L* Y5 v1 E, T* q. }/ ~% R4 A8 T. b- f0 {6 r7 B
在 SpeciaTheme 网站购买 Heropress Pro 主题后,从下载链接中下载主题文件压缩包。$ p$ f4 g8 e2 l+ z" x! g
; S4 b% ?; M4 E- K& y2.创建 Typecho 主题目录# H2 l3 s( o2 h
: \) K& R) C4 S: C: z/ p
在 Typecho 根目录下的 usr/themes 目录中新建一个名为 heropress-pro 的文件夹,这将是新的主题目录。
$ S' m. P5 a. y; Q/ Y: s5 N* |( C# e
3.解压主题文件
3 E4 [6 D, A5 t" h% ?: H- K
5 F, M7 e" w+ X' s; W1 v# F m将下载的 Heropress Pro 主题文件压缩包解压缩,然后复制文件到 heropress-pro 目录中。应该会有以下文件和目录:
! C( j8 K5 Y, ^; Y- g9 @9 |9 ^+ U9 ?
assets/
0 \8 @& e9 Z1 u1 [dist/8 \( A; r6 N% h& o& A0 J
inc/
! z8 ^4 {% y! O v8 {( D9 gnode_modules/
- j1 `5 j4 ? o2 t \! gpartials/
4 Y% r3 x8 X- h) l4 Utemplates/: N1 x4 V/ P+ j9 J$ o# ]7 |
.babelrc
2 v c% G8 p; H. p/ ].eslintrc.js
, A) B; @. M1 g3 k/ E, qgulpfile.js
9 p: {) h5 S8 A6 {: h, n5 d! u, \package.json
' d1 z! Y$ W6 S3 {webpack.config.js
$ b9 a0 K- R* A: o4.修改主题样式表文件
2 e6 O2 b+ X u
: N3 o/ x$ Z" L, j' R修改主题样式表文件 assets/css/style.css,将其中所有图片、字体等路径都指向 Typecho 主题所在的地址。例如:( g b* E- E: Z6 [
% G0 J# j1 g- A1 w% S* y! Q
css
/ f2 }( e) M6 \; Zbackground-image: url('https://example.com/usr/themes/heropress-pro/assets/images/bg.jpg');1 |2 l- J! p8 \% V0 L+ L2 [
修改为:
4 ] \% h* v" I/ i; t ]$ {, f
$ l! K) V" X. U( e9 e; e$ V$ Ncss& B S/ g5 O& c6 a9 V
background-image: url('/usr/themes/heropress-pro/assets/images/bg.jpg');
2 b+ b) ?! U3 f6 {5.创建 Typecho 主题配置文件0 ^; i8 a4 L7 h& D* {
' z$ m# e* ]1 Q" M# N
在主题目录中创建一个名为 config.inc.php 的文件,并添加以下代码:- V0 ~+ w' \& ~! \
1 O6 P4 @6 @+ k& a/ O: uphp* d* l1 [# L& \' a+ n
<?php
: ]# ?4 k0 @# Lreturn array(& L! Y: ?( w$ J8 {% p3 [9 N
'name' => 'Heropress Pro',
( z9 P7 d( j3 e! p; { F$ B4 }$ c. q 'description' => 'Typecho adaptation of Heropress Pro theme',! L3 z5 l% V9 O: r
'version' => '1.0',; g, n' I+ H! [1 n4 j8 c
'author' =>'Your Name',5 X6 X y7 P% @( {- ]# y( h
);+ n0 U4 {2 t5 s( h t
6.配置主题布局文件+ O/ l5 J' F j3 W
* R# x3 G1 u6 [2 F7 R9 o# M在 heropress-pro 目录中创建一个名为 index.php 的文件,并添加以下代码:
. f, \7 m g6 \6 M7 t% S4 v6 Z9 N
& o( Q; Q! t# q3 B! B6 Q- Q* pphp
5 P8 n2 w: l t! J, U+ H+ S1 ]1 |<?php while ($this->next()): ?>
1 o! b. L' L6 z<div class="post">
; M, c o- }6 M ^, _1 i7 n# v; A4 i <h2 class="post-title">
8 K0 Y; u; Z7 [ <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a> }% W0 `4 J4 q# x G
</h2>& v0 a) o. E( g; ?# s
<div class="post-meta">, e) U4 f( X# o7 e; E0 \# f; F
<span><?php $this->date('F j, Y'); ?></span>4 N/ { f* t* W
<?php if($this->tags): ?>4 f( J6 r5 Q0 i1 Q
<span class="post-tags">
- B2 d2 V. o X$ z, R& t <?php $this->tags(', ', true, 'none'); ?>2 R9 k2 ?- {4 I3 n
</span>
8 g! ~: u- q/ ] <?php endif; ?>& D: {0 w. A6 w- N; Q9 l
</div>+ a4 X5 U+ L$ l! v) t! `; N
<div class="post-content">
+ S& _* q p2 A+ s6 @4 ? <?php $this->content('Read more »'); ?>4 X( h# A% U" \4 @& N+ ~
</div>
3 c# Z, H5 {7 {9 x5 [</div>
, ^) Z' h0 `& K" o/ D- Q<?php endwhile; ?>7 z; j- ` x# u+ w
7.调用 Typecho 函数
) t9 w# _2 \4 L1 E" n3 I- l- X2 W8 R
在 index.php 文件中,将需要显示文章的地方改为 Typecho 的函数。例如:: f- t7 G: p9 s2 Z2 C! c4 S
" C2 L+ g* h' X g- D+ ?
用 the_title() 替换 get_the_title()。/ ^* }$ z& I9 S* Q. w, }% J. I( P+ P
: N" V% R5 X3 e3 w7 U用 the_permalink() 替换 get_permalink()。
' S! z' O" C ^
3 r3 ]6 Y, P& V+ w* }# Z4 n用 $this->date('F j, Y'); 替换 the_time('F j, Y')。
1 k: u0 u1 J, G% E* h: E
) W- T }* T" ~4 e& K2 p! m用 $this->content('Read more »'); 替换 the_content('Read more »')。
$ U0 o; l9 G1 W5 u
+ e5 y2 U3 [- N# d( A8.添加 Typecho 标记
2 T' D4 n% s8 K; r2 Y
8 a* i0 c( t* E0 e在 index.php 文件中,添加 Typecho 的头部和页面循环,以及必要的 js 和 css 文件: n; H b8 [2 v* V1 f
& [2 f) y; |% y4 {) E
php
3 @% @/ [6 m) Q! x, i& D<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
3 G0 E% R6 ~7 }+ s( Y<?php $this->need('header.php'); ?>
0 F& L( m i! W2 i, A) [; D- Z3 [<div id="main" class="container">- m' S Q, V/ H+ {/ E
<div id="content" class="row">) y9 e( G2 d4 J, p
<?php while ($this->next()): ?>4 N: z% M( B5 |5 t
<div class="col-md-8 col-md-offset-2">) j w; L$ `) z
<div class="post">6 K! I6 H, ?/ Q" u" x/ h
<h2 class="post-title">' n* g) b2 g: _- D9 }
<a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>$ D* P! D( w$ n T T2 Z1 S z8 p1 r
</h2>
; @* {9 E4 t" i& ] <div class="post-meta">
' R4 X; ]. V" u2 q$ t <span><?php $this->date('F j, Y'); ?></span>
0 U* s2 ` \) E P q <?php if($this->tags): ?>
+ O7 G& k& B, `4 R$ i, { <span class="post-tags">
0 ~2 N; _- B& c6 X3 H; O, m5 d1 Q, U <?php $this->tags(', ', true, 'none'); ?>
7 c& Q O0 N. R </span>0 I; F9 s& D A7 \
<?php endif; ?>! O" V5 [9 F) N0 k) K6 F
</div>
6 A( C$ t/ u2 a0 U <div class="post-content">9 n% K* u/ D$ v5 K! w" V# i4 b
<?php $this->content('Read more »'); ?>
0 k4 ?+ }, [# M5 R. j7 u5 D </div>, e& X: }7 O2 {! y
</div>
) i% _6 U. X8 X </div>, J# s6 |( o9 c0 J# Y3 \
<?php endwhile; ?>; ^5 ` X* W @4 u6 |) b1 [
</div>- {7 I9 {5 s* v
</div>
( S \# y- c7 h v1 h" @$ e2 J- W<?php $this->need('footer.php'); ?>
7 S" M( q* p) U8 J9.调整其他可能需要的文件和代码8 d: L) J7 a. r2 l+ A
% g$ y4 X8 j3 O1 C, l- R根据 Typecho 的特点,需要调整主题中的一些文件和代码。例如,需要将 header.php 中的 <title> 标签改为:1 u1 ~6 G# k/ H2 M5 y
: O) j5 |; A( o2 P8 [9 R: g
html: K% t% {; Z9 `, |* l
<title><?php $this->archiveTitle(array(6 w$ g5 V( {3 |6 X6 o; L- z
'category' => _t('%s'),
; D: I3 z: E p6 W3 ?$ `* W 'search' => _t('Search "%s"'),4 c( Q% r, u* ^& Q
'tag' => _t('Tag "%s"'),
. n6 }% m! R* U/ [) h: V 'author' => _t('Author "%s"'),. S6 s" P" f" A
'date' => _t('Archive "%s"'),
, [1 L( ]3 f% `# X z 'default' => ''
; W# x4 Z! X3 |2 I- }8 R6 H7 t ), '', ' - '); ?><?php $this->options->title(); ?>
0 }: W2 O4 `, s( D, W- E' E! s% v</title>
* p0 u- K# K( |1 `" m5 @ G10.使用主题1 Z. o! `% G: D9 O. o
8 s' `, b x$ F1 _7 ~% X8 s% J; J& e登录 Typecho 管理页面,选择外观,找到 Heropress Pro 主题,并选择该主题即可。: b+ _0 y. m9 `5 c" o: `* t
3 Q/ z6 w7 N# O5 p; D# F: ?以上就是将 Heropress Pro 主题转换成 Typecho 主题的具体过程,希望对你有所帮助。
+ a5 K8 R* |+ z. k
1 v/ T: ^& A# y) B$ d |
|