|
3 t5 E) k: |0 m: g# W可以将 SpeciaTheme 中 Heropress Pro 主题转换成 Typecho 主题,下面是具体的实现过程:+ }4 ^# K/ U8 \% N% S5 G0 b$ E' e
% r- h3 [8 b* n) }7 [' y& E
1.下载主题文件7 N! W. {% d3 w6 \6 C8 m* P4 _- a8 S
2 H, \; l% P& u; [7 W, [
在 SpeciaTheme 网站购买 Heropress Pro 主题后,从下载链接中下载主题文件压缩包。
& O. F6 C: P& y, r8 S
' Q8 R0 W& B' T2.创建 Typecho 主题目录
2 A$ J, }5 Y6 c7 X7 m( A* J/ F$ g$ C5 _! V: L
在 Typecho 根目录下的 usr/themes 目录中新建一个名为 heropress-pro 的文件夹,这将是新的主题目录。
8 x; a- T1 j- J' S; ^$ c& |6 \
. J# L+ ?# Q: p6 \3.解压主题文件
2 ?+ L" L# w4 Q' p( Q1 q6 [6 Q, a1 \1 a5 \$ T
将下载的 Heropress Pro 主题文件压缩包解压缩,然后复制文件到 heropress-pro 目录中。应该会有以下文件和目录:
+ }% x. f& _; W8 b
" L7 p; A; ]& H, p# y; k+ O! Y- y$ _assets/
! j' |% M( g1 u" w1 l! B* rdist/% c- f' C' F# b; x5 }+ a
inc/
, S5 X- B9 S9 F" K2 `- }5 Cnode_modules/6 @' S; L, V+ L/ l0 b/ @2 U
partials/
/ i: C( b% e& Q1 }/ e8 I G* [templates/
' q7 B+ m% W* V; n% O( X; y.babelrc
: z* o# `2 T: @4 o5 i$ L.eslintrc.js7 s9 @0 X5 y( W1 t. t. e
gulpfile.js
' n& M3 t' _5 x; g. gpackage.json
5 m$ Z' y: m* u. Z+ bwebpack.config.js
2 S) W. e) u9 g: i4.修改主题样式表文件
; {* I: m$ O! q: N* F
# A. }, a" k9 a% W9 F修改主题样式表文件 assets/css/style.css,将其中所有图片、字体等路径都指向 Typecho 主题所在的地址。例如:
2 T6 L& E! _; w j' {# |
- \+ K$ I; k9 ]( Gcss
4 D0 ?7 w/ S d( o% {; l2 D# Ubackground-image: url('https://example.com/usr/themes/heropress-pro/assets/images/bg.jpg'); i6 ~* U# ^9 M# W
修改为:; H# o% q1 ]' O' C% {
% p4 d2 O$ G' R7 v+ A
css
7 k6 x, f) ~9 [. h# sbackground-image: url('/usr/themes/heropress-pro/assets/images/bg.jpg');
/ P1 W! Y. ^: U" _4 s. k5.创建 Typecho 主题配置文件
3 K; u4 ~# ~2 a2 T% |: |$ z9 r
B/ o8 s6 I, ^" B3 g在主题目录中创建一个名为 config.inc.php 的文件,并添加以下代码:2 i% U9 D- j6 N, ?4 C
# W7 e3 ~4 X4 _, i; Aphp
- F1 w+ }5 D5 \" m<?php
' b! ?1 r0 a6 s8 w! [return array(
* [& D! C( D6 U* E z 'name' => 'Heropress Pro',
8 \7 R6 b2 h4 z5 W, b' C. J: X; q 'description' => 'Typecho adaptation of Heropress Pro theme',0 O+ d4 N: |0 z. f! i! Y% p
'version' => '1.0',% R* g/ d6 A, [$ M+ P$ Z
'author' =>'Your Name',
M# t2 W9 V7 d* x6 N) A);
6 d5 t0 E: G0 B' c2 ?* \; h' s6.配置主题布局文件
. w4 [: ~/ J4 f# U! U/ e [
L- G4 s- x' `在 heropress-pro 目录中创建一个名为 index.php 的文件,并添加以下代码:
! h/ I& c% H) f4 T0 [" a7 l
8 Q) E1 N! z. y$ q# \/ e4 b% \php
: ~: N( D3 D- ^( Y<?php while ($this->next()): ?>
1 W t' ~& J7 A( H0 D. ~; O<div class="post">8 U' Y+ n; X1 K% D' E
<h2 class="post-title">6 q) `) ]: W7 s% `0 `- }2 t9 T2 y$ T2 o! s
<a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>/ s( S5 \& p/ |6 }0 F5 y9 G
</h2>. J) J6 O4 ^% V. y4 o8 o. s9 A
<div class="post-meta"> I- o( h, y% F# V6 z0 z
<span><?php $this->date('F j, Y'); ?></span>, T" `1 y0 ~. c2 _6 Z
<?php if($this->tags): ?>
' ?9 R$ }8 K' z a <span class="post-tags">+ }/ o7 E, d/ \5 A" b4 Z6 B6 b
<?php $this->tags(', ', true, 'none'); ?>5 w) L `. m$ L9 `9 K7 p3 |
</span>
" Z/ H2 z7 a, m9 e <?php endif; ?>+ U+ y# w2 a5 h. @& z1 |& y
</div>
( e/ Q2 s! L* w" `6 ]: w. s' u <div class="post-content">
' P; S9 ^& E* m8 ]7 E( Y8 @5 s" x <?php $this->content('Read more »'); ?>1 R2 K* w, X- Y) e
</div>
- i, y1 b) `% y, }/ U* A" v</div>6 f: ^5 H# \. z6 ? Q- @$ ~) Q
<?php endwhile; ?>; T' F6 T7 i' t: `& n( a9 G
7.调用 Typecho 函数
. J" ~" i& u& t0 i- X
2 V/ y8 S S3 D8 c* p在 index.php 文件中,将需要显示文章的地方改为 Typecho 的函数。例如:
9 S. y- N2 X4 ^% G& q6 t) y
0 G7 h, p7 v4 }7 C- k用 the_title() 替换 get_the_title()。
' Q h' } I, |4 ]1 g- w9 Y3 Q0 D6 i( p! r$ k% V1 @
用 the_permalink() 替换 get_permalink()。
( J1 ^7 H5 h+ c; u3 } j s* p+ \
4 m% }! u4 h0 ?$ J用 $this->date('F j, Y'); 替换 the_time('F j, Y')。
+ N" W0 a' M$ \8 b
2 ?4 Q0 L8 f* v, |+ P! g4 m用 $this->content('Read more »'); 替换 the_content('Read more »')。; x2 B7 S9 Q* G8 H3 ~% J
- `8 U, _5 l/ H
8.添加 Typecho 标记
. O+ |! c$ B' @9 b
5 W" ^7 o* T7 n. P' E# z/ F在 index.php 文件中,添加 Typecho 的头部和页面循环,以及必要的 js 和 css 文件:
4 I8 S2 }5 M7 K# V5 x: C6 S$ I: s1 g8 u
php
+ c' R8 g! ~; b) s4 f' l<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
- @- `+ O5 t1 Y6 Q( M<?php $this->need('header.php'); ?>
+ F5 u: o$ ]* \. {2 C<div id="main" class="container"># h! i; c# \& y
<div id="content" class="row">
! z y, ~% J+ E6 g3 W <?php while ($this->next()): ?>
z) y- l: d1 C* [ Y9 q+ [ <div class="col-md-8 col-md-offset-2">; D/ y% b6 n K
<div class="post">
( C8 `! H% U( _ <h2 class="post-title">
. y) G" [) e0 W+ ~# D <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>
, e: O8 s% l7 Q3 t0 \ </h2>
" f. C& j, L5 u B& I i% R; n2 E6 q <div class="post-meta">
+ X& P' c5 Y+ z <span><?php $this->date('F j, Y'); ?></span>$ _, M( n& c. Y3 b3 h4 I. M |: c
<?php if($this->tags): ?>& j% {, G m2 D, C
<span class="post-tags"> e. l, W, b# V6 [; G9 s/ Y# C
<?php $this->tags(', ', true, 'none'); ?>
4 p: A L7 x0 g, s; m: r </span>/ k/ C d0 ?' ~; n' n
<?php endif; ?>4 t6 ~; |$ d' W3 {& ~1 X" O
</div>9 b9 G" [! X' L, C: D; y; V" {# I
<div class="post-content">
/ h3 L/ }9 r" O0 T <?php $this->content('Read more »'); ?>- k1 P0 R) v8 ^1 s4 c. s& @6 W
</div>; V7 |& g1 e, P, Z( k4 I8 {1 G
</div>
+ X+ G1 {6 U5 C3 @, S( g$ h+ o </div>4 M- q r$ z: E4 }& ~& Z
<?php endwhile; ?>* ?$ M7 s R4 O4 b5 z
</div>
9 U1 d. H, x& G$ s</div>
% e# J, x/ a0 F0 ?( S Y. n<?php $this->need('footer.php'); ?>
- m" q1 Z- B' J% x" n7 p9.调整其他可能需要的文件和代码6 T, R2 m, k& t8 A6 K7 t
7 o; s4 d" F/ d, c根据 Typecho 的特点,需要调整主题中的一些文件和代码。例如,需要将 header.php 中的 <title> 标签改为:
0 [! v2 W% I2 r+ D6 [5 {! O R2 k {, G( ]0 n
html L' @/ T7 y7 C1 B1 Q; c
<title><?php $this->archiveTitle(array() ]7 C/ ]& C( V2 h
'category' => _t('%s'),
, U, @" H5 M3 |. F2 f p) F k 'search' => _t('Search "%s"'),
+ l& E5 O6 F: \3 { 'tag' => _t('Tag "%s"'),! O! q/ L2 Z2 A3 D
'author' => _t('Author "%s"'),: H1 U% K2 i& o& E5 W
'date' => _t('Archive "%s"'),
% d! {- E1 q( R8 i 'default' => ''
% H0 A/ @# I1 s2 f' X ), '', ' - '); ?><?php $this->options->title(); ?>
( w+ J: n, E$ O) w3 `, {2 w8 Z! P& K</title>7 |& _) g. O1 H8 H' A! d% s
10.使用主题5 x3 ~7 ^9 Z% B, t2 w/ P5 o2 `! V
0 S7 {; {& ], b9 e+ r
登录 Typecho 管理页面,选择外观,找到 Heropress Pro 主题,并选择该主题即可。! b$ |6 s1 [: k4 K* k) m5 z ]8 e( A
- B0 Y$ v8 Z' J
以上就是将 Heropress Pro 主题转换成 Typecho 主题的具体过程,希望对你有所帮助。
5 |* F; B* \. `
* g* I$ j) S7 o* E |
|