|
1 V7 b) g5 p7 n( s8 |
可以将 SpeciaTheme 中 Heropress Pro 主题转换成 Typecho 主题,下面是具体的实现过程:
1 P0 q: b/ ^. I( J- I
v: I2 P' K8 W6 d1.下载主题文件
* d. S8 t: p' H. q. x* U0 Z$ Y& u4 {6 ^% h3 m% A% Y- e% C
在 SpeciaTheme 网站购买 Heropress Pro 主题后,从下载链接中下载主题文件压缩包。8 v% Q+ C- E5 Z4 b
5 u; T4 p3 }; O) B2.创建 Typecho 主题目录
, b) h( z4 f4 U% W6 B5 M* N3 b* G# u2 t0 ^0 i4 L7 a
在 Typecho 根目录下的 usr/themes 目录中新建一个名为 heropress-pro 的文件夹,这将是新的主题目录。
2 ~2 W/ c1 p& n+ }4 _ A
( h# X8 h G3 | b, x3.解压主题文件
3 I; b/ I, f0 e! b2 d' J! e* @, ?8 j y0 ~. w& q, `& L
将下载的 Heropress Pro 主题文件压缩包解压缩,然后复制文件到 heropress-pro 目录中。应该会有以下文件和目录:! v7 X0 |+ _ W5 B. y0 @
: G4 U" a- ~6 r) W$ T
assets/# ~" S( M* ^$ _5 X% E
dist/
( b8 x$ t0 x6 U0 _inc/
3 ^. g% m3 @) Fnode_modules/1 Q$ A+ y# b, }7 _
partials/8 Z+ a9 Z! h/ b* h9 F* k% E9 b
templates/
0 L8 k+ ?. d3 ^.babelrc; x" i) \- g0 ]& z( N: U
.eslintrc.js
, o5 I C/ {! W% b7 D9 |& zgulpfile.js
& n3 e. @" ~- K' _- opackage.json
& n. H$ k/ Y& f1 ~webpack.config.js: ] w3 k8 x$ T
4.修改主题样式表文件+ O, `6 S9 N& ]. e
7 a! ~5 |5 e; U" C2 c+ J修改主题样式表文件 assets/css/style.css,将其中所有图片、字体等路径都指向 Typecho 主题所在的地址。例如:( J/ E8 _0 u' |3 \8 j/ c
. K/ r7 ^' G6 a2 g8 G0 jcss
" `+ A7 Z" B+ N3 `8 {0 x+ pbackground-image: url('https://example.com/usr/themes/heropress-pro/assets/images/bg.jpg');& K1 Q- f9 o: e0 m/ k9 Z+ B
修改为:! }; d+ q/ h, `2 {' l
3 Q9 S) ?" E# b$ g0 {css
* x8 J1 k7 O8 \background-image: url('/usr/themes/heropress-pro/assets/images/bg.jpg');' l1 P, s* d& c, a) s$ Q+ B$ z
5.创建 Typecho 主题配置文件
r$ ?# U1 f0 ~
2 r& \( s4 ^% m/ d6 G$ \在主题目录中创建一个名为 config.inc.php 的文件,并添加以下代码:/ n1 [; j5 K2 `) ]: S( k
7 h d8 C @* K
php
! ~2 e9 U7 _6 G, B/ M1 d# N: B<?php) N$ p" a/ K9 `8 {4 _) L5 g* J i
return array(
; m5 p6 [& M3 i. I5 P% C/ \5 O 'name' => 'Heropress Pro',
+ @3 \3 ~9 f9 c* N# |9 t6 @ 'description' => 'Typecho adaptation of Heropress Pro theme',* n9 Y+ S) Z$ X9 f+ Y
'version' => '1.0',
- H) B& `& i5 w 'author' =>'Your Name',
9 o8 i9 `/ w: @2 x+ @# l);
( A5 R5 K/ t; g6.配置主题布局文件/ ^' Q# Z+ V$ n8 K
) ^% q0 o& P' y% U7 f4 d在 heropress-pro 目录中创建一个名为 index.php 的文件,并添加以下代码:4 D$ o6 @* ]) i7 f7 S
" `# r, P f# Y \php
$ M3 }1 c% N+ j! M | ^<?php while ($this->next()): ?>* o k$ O( @; y% U3 p
<div class="post">
0 u% k0 t) m8 ^, A! v <h2 class="post-title">
6 Z) l+ [0 @" c& g <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>
# S# Y, v8 N; |5 H# O </h2>
7 _% t. o- f0 @9 [$ @$ c; i, ] <div class="post-meta">
* I6 @+ Y9 n# j+ X4 Z# A <span><?php $this->date('F j, Y'); ?></span>
8 J6 f, K3 M: z6 g' R+ L7 [6 B. ? <?php if($this->tags): ?> }4 X+ Q3 J' t, V
<span class="post-tags">
& S T p! {& l* E( }! R/ r, ? <?php $this->tags(', ', true, 'none'); ?>
0 S, B1 F' t& [# f8 T/ s </span>( g, m% t* @9 G( I5 l! }! }
<?php endif; ?>
2 j5 w" X- b# D' k </div>7 c6 S3 L6 m2 N, q
<div class="post-content">
& F0 @# W* B% ?" v. R <?php $this->content('Read more »'); ?>
" O* t. h* J6 z/ D( P3 { </div>, }0 }1 v; H, i/ H! K0 S3 q
</div>5 x: ]; m- n5 x# @0 I
<?php endwhile; ?>
" A% ?: U) |! e$ ]5 @7.调用 Typecho 函数6 ^+ r3 e" C8 {! M a
# g ^$ C% m; Q0 m* B
在 index.php 文件中,将需要显示文章的地方改为 Typecho 的函数。例如:
% N6 q, Z2 T6 b5 f% R) \. i7 ^
) z. w" w F4 o9 u3 N: t9 K" Z用 the_title() 替换 get_the_title()。) W5 }( m( G" U; o
$ A" U4 @% m2 a7 F4 v1 r) F2 p4 a用 the_permalink() 替换 get_permalink()。0 k* c. H4 Y; K' x9 X
" \* {7 c& c% x4 u6 L/ V& M用 $this->date('F j, Y'); 替换 the_time('F j, Y')。
5 M& W( L& x2 @0 z8 a
" J# Z2 [+ e0 I2 b$ u4 T% V用 $this->content('Read more »'); 替换 the_content('Read more »')。2 z+ s' y) `7 z& q8 O% J) o2 d; Q
+ r) \# h6 X7 V5 [% H4 ?* }8.添加 Typecho 标记
q- Y3 C+ ?" z% u1 ]/ B7 U2 G. ?; d
在 index.php 文件中,添加 Typecho 的头部和页面循环,以及必要的 js 和 css 文件:( s5 t( M8 v* F0 ~1 a7 K
. ~9 y9 b7 ^4 H6 c0 o7 p1 ~, s
php3 j3 L4 v+ N& U
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
4 F+ J! c7 E6 Q<?php $this->need('header.php'); ?>/ i b) \& a+ W
<div id="main" class="container">
& t* X5 W4 R. P7 Y; ~0 ]+ _ <div id="content" class="row">9 X2 j9 A% |4 E% r
<?php while ($this->next()): ?>( w$ g- c: r S( ?
<div class="col-md-8 col-md-offset-2">* f, l0 _6 [% p- [4 f1 z. B
<div class="post">' ?! w! v, [4 i+ H
<h2 class="post-title">
) l( h# k* x0 M* u) n8 _ <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>1 l3 q" G3 r2 B' d$ V
</h2>, o$ C+ T* c/ ^3 n
<div class="post-meta">
1 V7 O) e& T; r: ~ <span><?php $this->date('F j, Y'); ?></span>
& P1 t- I/ v& V w8 p$ N8 l/ q& B <?php if($this->tags): ?>
8 y X; l1 A& v3 g7 Y' J5 p <span class="post-tags">
+ S5 C3 y% s3 j3 Z; j0 g <?php $this->tags(', ', true, 'none'); ?>
9 R2 U" N# z G5 ^ x9 k K </span>
0 y |. D. e* i5 [2 c$ s4 m2 D <?php endif; ?>, ?9 ~# q3 a7 x( J2 c
</div>7 n1 }/ W! ?% I0 p5 z- ~4 e$ z
<div class="post-content">7 j7 l1 e; e) [9 Z; Q4 \
<?php $this->content('Read more »'); ?>
3 ~- Y8 r8 D2 L$ p+ N# }* f </div>
# ?+ y& ~7 h$ y3 z </div>
8 ?! B' P6 z9 ]# M </div>& J+ `& s3 l. b4 s$ o
<?php endwhile; ?>" @0 n% o: Z; k9 O
</div>% G8 V, A% a& `3 |* S9 q2 z* H
</div>7 J, h# ^) Y, J6 g5 Y& g
<?php $this->need('footer.php'); ?>
1 l4 `0 v9 U5 q# X& }9.调整其他可能需要的文件和代码
! k Q7 k# V5 ]+ U# ^: ~ g/ R1 c8 o! X5 A# @- X% Z. N2 y' p. g
根据 Typecho 的特点,需要调整主题中的一些文件和代码。例如,需要将 header.php 中的 <title> 标签改为:
5 u( f6 T, Z' z8 A- d( [" K& \; y s7 B4 s( `( I- ~+ Y4 _
html
' v1 |% p" ]9 d( U<title><?php $this->archiveTitle(array(* X) K6 ?1 O* I6 ]; u( p
'category' => _t('%s'),
+ I! K' z9 ]4 K6 @# Y" g b: G 'search' => _t('Search "%s"'),9 T6 ?3 W6 y' u% V( j& Z3 W
'tag' => _t('Tag "%s"'),
2 X/ T* t$ j2 Q: ^/ u) a+ N! I) Q 'author' => _t('Author "%s"'),
( D6 ]" K0 V5 R: t2 f' L) K 'date' => _t('Archive "%s"'),
. c [0 `5 g. {3 W& X. C3 j 'default' => ''
2 N, w; k7 [/ P* f) X# Z& Z# ~ ), '', ' - '); ?><?php $this->options->title(); ?>2 [5 a( c0 u1 ~- e1 |6 Q* s5 ~8 `
</title>
K5 _7 J; Y ^10.使用主题
& R7 _4 k2 L8 j4 p
' `! c6 c6 t: E, h0 p& m登录 Typecho 管理页面,选择外观,找到 Heropress Pro 主题,并选择该主题即可。
2 U4 N( f ^+ J+ ?
* P1 n" |, s7 u0 o5 `0 U& E, c2 ?以上就是将 Heropress Pro 主题转换成 Typecho 主题的具体过程,希望对你有所帮助。
$ ]- ]; S+ L1 @
0 v" g1 k8 _8 c; F( C% X |
|