|
|
9 j( w/ E0 v" g: q+ E7 R( D可以将 SpeciaTheme 中 Heropress Pro 主题转换成 Typecho 主题,下面是具体的实现过程:! W! S% E) B3 B3 m1 n- T
9 P+ A6 Z+ B5 z3 V `$ F) x. `' i. A5 \1.下载主题文件
# m# ], j( f( I: o( Q; S$ E
: h" Y3 X* W, S* p在 SpeciaTheme 网站购买 Heropress Pro 主题后,从下载链接中下载主题文件压缩包。
5 r. k% S4 [* u& [' u9 w8 ~ T; y9 e' b& w# E3 Y
2.创建 Typecho 主题目录
! J5 v/ r! O( L6 N' h$ B3 D& b2 G6 O. s5 i
在 Typecho 根目录下的 usr/themes 目录中新建一个名为 heropress-pro 的文件夹,这将是新的主题目录。- E# r' f! M. F8 x4 p0 X( h
% ]) n1 i E$ a% Z: t2 y$ j3.解压主题文件
$ u% H# f) S$ o) ~* o+ ?% l# R. i- j1 K, t
将下载的 Heropress Pro 主题文件压缩包解压缩,然后复制文件到 heropress-pro 目录中。应该会有以下文件和目录:/ z, X; v! K; l" F, l
1 ?0 ~, \, B% r; u- \assets/
* m9 z, K a1 K8 c& w/ Wdist/
$ j3 k h0 A4 ^ q. G/ L3 I7 Einc/7 T! ~$ W8 L) I8 C# v- O% {6 G
node_modules/4 t* H# a* c" q0 e
partials/
5 A3 S) x9 Z5 I) ~' {templates/( c0 n2 L7 k, `+ h
.babelrc
7 {% H: Z1 m4 p.eslintrc.js3 C7 T- s$ q7 e7 n, P
gulpfile.js! {3 h& _$ i" e8 a
package.json" B7 G2 o( N: b! J, E h" p" a
webpack.config.js
0 q! p- P, r) H# D$ f: A4.修改主题样式表文件8 s& s# H! u% e8 E% w
- Y* v/ [4 t! Q2 R; m& ]修改主题样式表文件 assets/css/style.css,将其中所有图片、字体等路径都指向 Typecho 主题所在的地址。例如:1 [7 c& R# V' q) k& A
% T: l& f/ d6 S
css
% q9 p$ ]/ K3 h' |6 z4 M) }5 h# ?background-image: url('https://example.com/usr/themes/heropress-pro/assets/images/bg.jpg');. A; x/ f2 C- ` F; a' m
修改为:, M0 l2 g$ ~! a; R( S @1 w
O! }( e, d F M* c9 fcss$ M" x& z: C" k. A! r8 c6 `
background-image: url('/usr/themes/heropress-pro/assets/images/bg.jpg');
/ F& a3 d3 u2 r3 v5.创建 Typecho 主题配置文件( K# m2 C" q9 B) K- P4 x
4 \; f" O1 I! | P3 a在主题目录中创建一个名为 config.inc.php 的文件,并添加以下代码:
( |$ d9 a9 {8 }: b$ S, c* L3 Q+ @4 @5 G* q4 _
php
/ ]1 W9 N4 V; Y0 a% w, x2 w1 U2 f<?php2 B# o/ Z {8 t' l- w
return array(0 ?0 W; S# ]6 H( c- t6 p
'name' => 'Heropress Pro',
8 {+ V. [0 F% u 'description' => 'Typecho adaptation of Heropress Pro theme',
" F! l0 _6 t& b- S. C J: t3 ]0 `; R0 { 'version' => '1.0',
" x: Z! Z; X/ `/ B 'author' =>'Your Name',
0 q9 p$ A. @* P" D- `, D% ^# H" H);) ]% I$ L/ Q' I/ ~( s2 F
6.配置主题布局文件2 y4 S! j' w- e/ s1 ~
$ p. r, R3 v4 c5 `2 @2 P
在 heropress-pro 目录中创建一个名为 index.php 的文件,并添加以下代码:4 L* L \# _6 X. }- ^. l2 g; p1 t! f' i
" Q7 U! y6 T/ tphp' }" b7 y, K8 N; n$ r
<?php while ($this->next()): ?>( F( ~1 Y3 g3 J2 P, d
<div class="post">- S, q& V) q0 v; C2 m; \: H1 ~
<h2 class="post-title">
( b' u" l6 p: g/ N" ]7 i9 a. a <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>
! n. \+ L; ?, l& v3 B </h2>
% x& H8 @; U" p- p <div class="post-meta">
m* E& T" w, Y* k3 z <span><?php $this->date('F j, Y'); ?></span>- l( s: e1 V1 D; H
<?php if($this->tags): ?>7 H3 @3 H, N4 A; C( |. h1 |
<span class="post-tags">
) O$ r/ s. M4 G& T* } <?php $this->tags(', ', true, 'none'); ?>
% }6 ^- K6 Q1 Z7 Y$ I- C* H </span>; [, a8 q4 N5 J; b
<?php endif; ?>
% ^( D% _4 T: d </div>/ a9 A' y# w- w
<div class="post-content">2 v+ e1 c7 |, ]- V, V+ |
<?php $this->content('Read more »'); ?>" w p7 a# G4 O% k; d4 L
</div>6 @; u" Q, L. O
</div>
4 R; x8 k" x) c A% v- h7 t& k8 T- F<?php endwhile; ?>$ z1 Y2 w3 g9 x
7.调用 Typecho 函数$ V* M: I) [ y# f
) A" F$ C: S' v1 p) S6 A在 index.php 文件中,将需要显示文章的地方改为 Typecho 的函数。例如:# d- t6 }4 w5 x6 n# \; ]
" ~* R! }: k4 m4 B& d用 the_title() 替换 get_the_title()。
+ V- @6 D3 C4 e7 c p% n/ T& B4 u9 F+ u1 |3 K' j
用 the_permalink() 替换 get_permalink()。. T6 c; K0 Q" e' n$ q
1 f6 }% p$ t( X' V/ i$ @3 T
用 $this->date('F j, Y'); 替换 the_time('F j, Y')。$ |: Q k$ G. b. @6 ?
8 u- ~* |' z. g( r- V! }" {$ w1 U
用 $this->content('Read more »'); 替换 the_content('Read more »')。$ |2 d: j. o: O3 @
- l: \- ~5 v0 A, J k; c
8.添加 Typecho 标记5 i5 E* r( c! I& k, J
, H, C8 q$ `& }8 d6 \在 index.php 文件中,添加 Typecho 的头部和页面循环,以及必要的 js 和 css 文件:
$ D7 w6 p" ^' B+ I! J6 j' C5 ~2 f& I( M1 |5 X9 c
php% j* r6 n, t0 [3 k. \; o/ S! }7 Y
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
) |; i3 L7 \9 ^$ \ ^. c<?php $this->need('header.php'); ?>/ R* A# B0 `# f& d# J1 x1 m8 b- R
<div id="main" class="container">
l; K: J! R" k# s4 u <div id="content" class="row">- H9 ~, d3 j" W; p
<?php while ($this->next()): ?>
a0 O! q, d- r* Z& Z* P <div class="col-md-8 col-md-offset-2">
/ |/ h$ l: I0 ]6 W& j; s4 I <div class="post">
( q. Y, z: a: i/ s+ S' L3 X <h2 class="post-title">
0 X j+ k: E1 ] <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>& u0 Z8 r& z7 j6 \' V8 z, S$ d u& O
</h2>! N/ c1 U- P5 |# N4 a5 g% t: H
<div class="post-meta">
8 ~5 r, M5 e3 ~1 h8 [$ C- c <span><?php $this->date('F j, Y'); ?></span>
0 w% W6 d* D; X <?php if($this->tags): ?>7 I/ N/ ~1 O$ |; s$ {
<span class="post-tags">$ n9 ? T. A t( L) H0 P3 K
<?php $this->tags(', ', true, 'none'); ?>5 ]0 D' E5 _/ c$ {" B* _ x
</span>7 L% K, a! J7 b# v7 B
<?php endif; ?>+ C& Z2 |- ]) [) j
</div>
, r& D: n9 F8 s8 b <div class="post-content">3 P" b( H6 ?5 v3 ?, w$ M8 N
<?php $this->content('Read more »'); ?>% h6 k$ d( k6 `& p _" V4 c
</div>; r: J7 A3 \ _! s1 N. h
</div>: \/ ^/ Z9 S' R0 P2 P$ F$ _
</div>+ V! ?8 I5 k- V
<?php endwhile; ?>
8 ]. E3 q! M8 T/ \& W </div>; ]" n2 n3 c+ m8 z; r
</div>' p" [' ^. Z8 V" [& p2 S: ]
<?php $this->need('footer.php'); ?>/ Q5 L+ _% K# i% ?( h7 e
9.调整其他可能需要的文件和代码
5 l& u& k% k/ }$ S2 A) q2 ]! M# U: B: u
根据 Typecho 的特点,需要调整主题中的一些文件和代码。例如,需要将 header.php 中的 <title> 标签改为:
7 R7 u' X e4 `( n7 B' f, P& [. \, ^# l
html
6 A! @. h' l/ Z& N+ \' S% z* a) ]<title><?php $this->archiveTitle(array(
. Y3 }. Y& v4 x J* P 'category' => _t('%s'),
# c0 z* t: W @+ C; e: n; Z7 C) q% @ 'search' => _t('Search "%s"'),% a$ |: E+ A7 ~
'tag' => _t('Tag "%s"'),
, m0 }' T0 _+ K- l+ h! X 'author' => _t('Author "%s"'),+ L. ^/ H+ y2 Q, r( ^
'date' => _t('Archive "%s"'),
4 b7 h2 y0 L2 {- D7 I: ~- R; U7 u 'default' => '') C$ k/ I0 F) c" G8 q
), '', ' - '); ?><?php $this->options->title(); ?>" z! b, o8 B6 J; h
</title>
4 Y5 _2 c% |% C/ U2 F10.使用主题2 {( h$ ~5 J+ V! m& k
, w: j6 F& v4 c% R% h4 @/ i% o8 j登录 Typecho 管理页面,选择外观,找到 Heropress Pro 主题,并选择该主题即可。
( O5 T8 `' T9 ^5 l, k9 i7 ~5 @0 }) R% I2 T$ @
以上就是将 Heropress Pro 主题转换成 Typecho 主题的具体过程,希望对你有所帮助。
: p, Y3 ?5 m% i
. K l, G: @6 ~ e. _' S) {& X |
|