|
|
( h' c: J6 g. v" \& A2 d可以将 SpeciaTheme 中 Heropress Pro 主题转换成 Typecho 主题,下面是具体的实现过程:
3 }5 [5 W) H7 N" l+ B1 [" L% g$ D6 j+ P8 B3 B2 `6 d5 r
1.下载主题文件
6 ]/ g# S' | s
$ z+ E' ~$ w" {6 a! f9 z在 SpeciaTheme 网站购买 Heropress Pro 主题后,从下载链接中下载主题文件压缩包。; H" }9 v" a- n) Q7 g
( d: K# z" A$ \8 h. d/ G2.创建 Typecho 主题目录
0 N( ? W+ F: Q, n
% Z1 q' O% g( M在 Typecho 根目录下的 usr/themes 目录中新建一个名为 heropress-pro 的文件夹,这将是新的主题目录。
$ Z' ?+ f( |3 [5 [* R
/ C2 v2 F0 X: h3 b1 R2 c3.解压主题文件
- G7 k$ r2 V+ {3 c6 d
; x u" `3 s: q e( E R ?将下载的 Heropress Pro 主题文件压缩包解压缩,然后复制文件到 heropress-pro 目录中。应该会有以下文件和目录:
1 J; {" e# d8 Y* O
, K2 ]1 ^0 d+ a: u6 lassets/
1 y+ I. m2 d1 ]. o5 Edist/- V! v1 `+ z0 \4 b* ^# [
inc/
: t6 g" ~" R2 L' Y* c# Dnode_modules/
) p3 P: o% A4 j, u, V# zpartials/$ b I! H' j' [' {
templates// f7 B. q$ J+ V! |3 g
.babelrc( L5 K7 K5 E: R! A
.eslintrc.js
# l* ~. z; s+ m& @$ T* Q9 Ngulpfile.js
" K/ i7 g% X' b& O3 fpackage.json
3 ]6 l' ~& j! H1 u" |1 Xwebpack.config.js/ [8 w2 A0 f: O# \# [
4.修改主题样式表文件+ V) K$ S0 i' |- C1 v# J4 m, t' ^
8 ~& E7 g: c+ b! _, I4 ^修改主题样式表文件 assets/css/style.css,将其中所有图片、字体等路径都指向 Typecho 主题所在的地址。例如:5 R9 x* t+ m$ |1 l& l
, }% C5 `8 q2 r$ R% N8 c! U" icss
5 y# b" h9 K0 y$ @3 a- k! W3 b( nbackground-image: url('https://example.com/usr/themes/heropress-pro/assets/images/bg.jpg');
( z* M& _) ~9 T( ^' e; `修改为:1 |5 s8 {1 S" V- n* R: r7 N
! p3 X! d5 i! E, Z9 Z$ L2 mcss
9 h# O# c6 _& Q; J4 f& sbackground-image: url('/usr/themes/heropress-pro/assets/images/bg.jpg');7 i) I3 D3 s. \1 [9 a7 E& O4 q
5.创建 Typecho 主题配置文件
+ H) r1 @( [+ {+ {& k
+ e9 c! V7 [3 a在主题目录中创建一个名为 config.inc.php 的文件,并添加以下代码:$ p6 y: C* h! K
; a( Q% v0 p, p+ aphp
& _* I8 t! O1 z$ w& q4 @<?php" K5 Y7 \( a4 m
return array(! x1 E* k( n6 J) w4 w% G$ k5 r; _
'name' => 'Heropress Pro',
: R( L) U) {) ~- {# K 'description' => 'Typecho adaptation of Heropress Pro theme',
; P8 D+ z; h; m+ Q# d 'version' => '1.0',! G) q. Q# M, s* `2 G1 F% b
'author' =>'Your Name',; a) S, P7 \5 D& p' O+ i2 @3 \
);
2 F$ F4 f; s8 G8 U" Y% t6.配置主题布局文件! h/ \9 l' o% K' w }
0 }/ Q9 l6 ~0 Q0 r在 heropress-pro 目录中创建一个名为 index.php 的文件,并添加以下代码:
0 A& W( J+ \2 G6 q" \
; n/ `, l5 S8 \4 gphp; N3 D# Z; U7 j5 i' ~+ ]! @
<?php while ($this->next()): ?>1 i& v$ ~5 S5 j& e
<div class="post">
1 ] A. P' z2 X4 P5 } <h2 class="post-title">
" a' ]. b* |. h4 _/ E <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>8 }7 k$ P; c6 Y. I: X: f+ c
</h2># F' [1 t) v# s! C
<div class="post-meta">/ p3 e: o9 S* n; M; G
<span><?php $this->date('F j, Y'); ?></span>
' n) n# ]5 C8 L <?php if($this->tags): ?>
$ S- z" ?# r- v0 s, v* V <span class="post-tags">
2 n* f9 v5 ?) B9 P, y0 A <?php $this->tags(', ', true, 'none'); ?>" U: F! s, I, \, t! A
</span>
# Z6 G+ O0 S+ y6 e$ v' ` <?php endif; ?>6 O O+ ^( V( d) r
</div>6 l1 o! B9 S9 L8 L- M2 ]& H% i
<div class="post-content">% s; v2 f$ W# f a8 W3 _
<?php $this->content('Read more »'); ?>) T! s* S) d" J4 n
</div>
: T( M, D$ l" |+ Z# D, y% `</div>
, j! j* s, u) w' e" \! h# {/ [) g# E<?php endwhile; ?>
+ b3 ]7 G5 ]# P) ^% s7.调用 Typecho 函数* q4 t, v7 s' H
}$ q( M/ M% m2 b$ `$ i, b# C) r
在 index.php 文件中,将需要显示文章的地方改为 Typecho 的函数。例如:% b* {" \+ U) O# j0 j% o
4 B& Y. H/ y& V% s5 w0 `8 M5 _用 the_title() 替换 get_the_title()。' i$ w ?: {. j7 i
* F, n) S- N- C9 x: W2 z& L; p9 B用 the_permalink() 替换 get_permalink()。
. _' a" r5 S& n9 }* r2 l/ g. ?- H& i1 A: c: N+ R
用 $this->date('F j, Y'); 替换 the_time('F j, Y')。
' c; e9 M" r o: h/ H( r6 L
) k$ k" e2 X- N. _9 P [' \/ s) D% H' Y用 $this->content('Read more »'); 替换 the_content('Read more »')。/ x c3 ~" j1 j1 G, k6 ~4 t9 ?
4 h7 V) G3 j! o8 E' A1 R7 `* ^6 M% T8.添加 Typecho 标记3 W: i+ S$ ~# U6 G, e' i
1 Y1 T! u4 x* W( m! }/ E8 Q" K6 e在 index.php 文件中,添加 Typecho 的头部和页面循环,以及必要的 js 和 css 文件:( r$ H, {3 X( t6 q% u$ @ u
o: K2 d9 z7 P+ S/ o& ?php
. A+ I8 X ^! _8 W E3 ~) C<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
5 a5 f; C; n6 Z2 g<?php $this->need('header.php'); ?>
7 [1 S/ ^3 e$ q2 y+ } H$ v& _/ T: h/ `<div id="main" class="container">, n2 o0 N) P' m7 g* W9 Z
<div id="content" class="row">
$ C+ \7 M! |' K' o2 t- d! p <?php while ($this->next()): ?>$ ]" ]$ X& f2 f+ d! s1 D# K3 M3 C8 L
<div class="col-md-8 col-md-offset-2">' z4 \8 H8 I9 I3 I% i3 h
<div class="post">
: p* c) E2 [& L& P8 D, }, Y8 c <h2 class="post-title">8 }$ F$ S8 f6 n0 Q& f. q: ~! d8 f
<a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>
- \0 J7 J$ o8 \$ E$ w/ s0 t </h2>9 O( R3 ]; @. A" s' g
<div class="post-meta">7 d0 K. t) p) l& A0 ~, d
<span><?php $this->date('F j, Y'); ?></span>
7 Z! e0 v( V9 a, }$ v, A) G <?php if($this->tags): ?>
4 o2 g( K- K2 { <span class="post-tags">
! e1 K5 c- E/ Y7 h <?php $this->tags(', ', true, 'none'); ?>
8 i p+ Y& G/ F# ?, J, H& g5 D </span>
2 f" w. C" ^" `8 l3 b <?php endif; ?>7 l/ M5 X- i' U7 y
</div>, X! {( c. o2 x/ A+ B
<div class="post-content">% [! M9 B( D: H" l
<?php $this->content('Read more »'); ?>
7 }: V' P% o, @7 y W( ? </div>
$ Z! H+ f7 z; {/ [7 I </div>6 ~5 T0 B4 m" p9 l4 S( J
</div>6 l" Y4 U9 ?& y
<?php endwhile; ?>1 `4 [9 f- r# B' |5 Q/ J- C$ T. ]/ X4 K$ [
</div>
; E$ b8 \0 B" o" M</div>: h* j+ B: f2 ?3 D1 F; p3 I) L7 z! j
<?php $this->need('footer.php'); ?>
) R0 u' o; q# M" n& x) r0 w9.调整其他可能需要的文件和代码4 t: z& u. D" S; W
+ v- V4 n2 f4 j5 o( e根据 Typecho 的特点,需要调整主题中的一些文件和代码。例如,需要将 header.php 中的 <title> 标签改为:
" [- A) `% X. P/ L) j% m% _0 i. ^7 n% ?. S1 Z. F
html
# A2 G# \7 d' P& _3 Z- ~) p* `) D<title><?php $this->archiveTitle(array(
( @, o% J: I9 V% ~5 T4 B7 p 'category' => _t('%s'),& S" q$ f. ~2 `, T9 |0 B
'search' => _t('Search "%s"'),
/ ]: O% _ j! [& B) _- { 'tag' => _t('Tag "%s"'),
: Y0 E9 U) e. u+ w 'author' => _t('Author "%s"'),; ]' ~6 g6 Y% {0 t: g
'date' => _t('Archive "%s"'),/ t& I. m& y8 `, G) D
'default' => ''
% W' `1 B) b( [ ), '', ' - '); ?><?php $this->options->title(); ?>
: I0 A% f T7 w& y+ R; a' K</title>
) y- }$ u, U( |3 {$ V10.使用主题
- y/ M$ T+ L/ N# x4 X/ u
( D/ B6 D, ^8 }$ @登录 Typecho 管理页面,选择外观,找到 Heropress Pro 主题,并选择该主题即可。
1 N3 `7 t i. K$ U G+ P7 b0 C% A; K9 G2 w
以上就是将 Heropress Pro 主题转换成 Typecho 主题的具体过程,希望对你有所帮助。
( I( e Q9 ~- |2 V! n3 \1 k
5 v P {1 S+ G/ J |
|