|
|
1 C$ I t, J8 s( [6 F" o7 q
可以将 SpeciaTheme 中 Heropress Pro 主题转换成 Typecho 主题,下面是具体的实现过程:+ I9 c/ O$ \6 ^2 t$ S$ U! k5 D- K: A
4 b% t' W! X |* ^6 r1.下载主题文件
2 T5 y; F( K% _, ^/ v. c5 R. G% N. F, I
在 SpeciaTheme 网站购买 Heropress Pro 主题后,从下载链接中下载主题文件压缩包。
9 u2 w. F/ f; J$ l
2 o, v, B3 @! y2.创建 Typecho 主题目录9 r& a( ^; C& _1 y7 c1 `! y
' E( F) x/ B7 k% z
在 Typecho 根目录下的 usr/themes 目录中新建一个名为 heropress-pro 的文件夹,这将是新的主题目录。
/ C, T9 q* K' f3 X2 j1 r0 G% k" f8 m3 r9 H" _/ S/ s& }, N
3.解压主题文件; E% G6 T& W& \2 c# b# @* O) a
/ T7 y! s1 r5 Q将下载的 Heropress Pro 主题文件压缩包解压缩,然后复制文件到 heropress-pro 目录中。应该会有以下文件和目录:
1 [' ]% r) w4 o$ [* }5 y# }' P( R8 x9 |( M
assets/+ X0 B! D m) R( R: J2 I% W# R
dist/4 v! m( z9 p/ U
inc/0 K; P4 F- ?: }. r1 S
node_modules/' u; J* j ^% e$ y7 D5 m
partials/: `0 U0 J1 h) j- ?
templates/: ~ H+ ]! Y, ^1 }2 k
.babelrc/ H3 K+ |' h6 w$ t9 I
.eslintrc.js4 d, }& G6 C0 ?% J- O# [8 N
gulpfile.js
8 o0 j- A3 }0 N2 _- {$ ypackage.json: e# U! U* m) g) B8 c
webpack.config.js! m9 ~- u! C2 ]. U' i. q
4.修改主题样式表文件* a. _9 ~& Q( w# C, e- ~
7 b$ R7 k: L9 Q/ ?) [) R/ B修改主题样式表文件 assets/css/style.css,将其中所有图片、字体等路径都指向 Typecho 主题所在的地址。例如:
6 @; U, F; J/ [; f7 W# O* q) ]8 o) }; P* e+ k
css! y7 o! o) w: ^8 N; W8 |
background-image: url('https://example.com/usr/themes/heropress-pro/assets/images/bg.jpg');' B# |" T! R0 A5 @
修改为:0 X Q; S8 c' q6 s% n0 D9 L
9 t6 c5 ]* W& T- U0 u% y% acss
5 N$ e8 Y% D6 L( @6 kbackground-image: url('/usr/themes/heropress-pro/assets/images/bg.jpg');. |$ X) u Y! }" |2 `( W3 L9 L
5.创建 Typecho 主题配置文件
6 @1 t$ E, P$ r' d2 c' H6 {+ ~1 R# Q' j6 ?% y
在主题目录中创建一个名为 config.inc.php 的文件,并添加以下代码:1 H. i# W6 S, y) q( A! _
, f% Q; {! S% [9 O4 |5 N& ~0 n
php4 P. g5 K# K$ R& ?: B% m: N; t0 [
<?php- @4 j0 y$ O7 \% ]7 h% K
return array(
; ^5 s. L8 h( M, u 'name' => 'Heropress Pro',
: G5 |# Y1 E8 d' G2 {$ F/ ~5 G 'description' => 'Typecho adaptation of Heropress Pro theme',
! H$ P N. N5 q, J" M4 n 'version' => '1.0',
' D( e! K. w; S! C, r% ~ 'author' =>'Your Name',
! K; X5 K5 d: O+ M);0 g" r4 \) T# Y$ e
6.配置主题布局文件
2 W0 E' K& f' F9 K; I8 `$ W
7 |) _" d0 N7 w9 c" [ V1 y在 heropress-pro 目录中创建一个名为 index.php 的文件,并添加以下代码:8 l) S) ^$ M; H; [4 N
% {8 ~4 G; S- f, ^/ i# A! Vphp
5 j* F: }; @: K- @/ I<?php while ($this->next()): ?>! f: L- H. D) i7 t) s
<div class="post">
! q0 X$ R& q! x <h2 class="post-title"># H6 ` m5 p7 g+ |+ @
<a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>1 ?# r# T# K4 y9 q4 p* P
</h2>
8 H# N7 q8 b& x7 ? <div class="post-meta">
) U O# h4 a/ W! v" Y& } <span><?php $this->date('F j, Y'); ?></span>
4 l( F2 o8 i; `1 ~ <?php if($this->tags): ?>5 g; w6 Z [& f6 K# ~' o9 R
<span class="post-tags">
( R+ F7 T8 k' S# ] <?php $this->tags(', ', true, 'none'); ?>
9 B- J: A s' q3 ~ </span>
( T1 S9 Y6 M5 v: J/ h) m% k <?php endif; ?>3 r# B5 O+ e A: O/ D
</div>
6 d+ o" A& k" F; D; E: T+ {- R. w- N <div class="post-content">
; X2 C5 S d4 \1 k& S <?php $this->content('Read more »'); ?>8 K8 n7 e* K ?8 W! i
</div>
4 F# k' r- e6 a! x6 D8 e1 N$ L</div>
/ P) q' z* g" L. v* \, S# {' {<?php endwhile; ?>' E# N( z1 ^( {( |( K9 s7 L
7.调用 Typecho 函数
; Y4 r1 d2 ^% [( F6 r0 ?9 ~3 D& R8 {3 w8 Q3 |, P5 I% n; L5 T
在 index.php 文件中,将需要显示文章的地方改为 Typecho 的函数。例如:
4 B) q: d3 T" x! _ ^) v1 E/ @+ q+ Q5 M- X" J2 C; q' a, M
用 the_title() 替换 get_the_title()。
, x2 K: f s, @* \3 V6 u2 e$ t
. C9 d6 H4 R! e用 the_permalink() 替换 get_permalink()。
/ G* y; Q$ S# \; V9 i
, l9 o5 Z% E3 X9 F' N* U7 p用 $this->date('F j, Y'); 替换 the_time('F j, Y')。
3 P& ~$ C U4 E3 |* B) M/ t' u2 h5 @2 t! s$ U) A2 \
用 $this->content('Read more »'); 替换 the_content('Read more »')。) a! ?8 T! K' X) O( x
$ H( M2 L7 D J6 u0 \8.添加 Typecho 标记* a, K4 L, L) d/ G
& s, K8 K1 Y% `7 h; A# @
在 index.php 文件中,添加 Typecho 的头部和页面循环,以及必要的 js 和 css 文件:
4 i! `6 u" q( C- x5 ^# z
5 [. g: s! b. K4 j4 i$ j7 _php
( ~& N7 I" v. L3 Z<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>/ o% `/ f- F [
<?php $this->need('header.php'); ?>
: J7 F# `0 p) T9 o<div id="main" class="container">- c! d6 F* p" G# I/ r" C
<div id="content" class="row">5 e" s( z9 J5 Y) {8 O, R: w
<?php while ($this->next()): ?>
3 [3 J" X3 [( J( X k# g/ p: N L$ r* U <div class="col-md-8 col-md-offset-2">
E7 Y. k( z+ t1 c( D <div class="post">& U0 L- F. }0 l1 d4 W
<h2 class="post-title">
) O4 v' c9 u- z' N: Z7 g. \' } <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>7 B4 J7 L0 k" B
</h2>1 Q: ^1 y3 E: j1 K* n$ j
<div class="post-meta">* p3 F0 b1 \& L8 e+ P I
<span><?php $this->date('F j, Y'); ?></span>
/ j* r& j/ @( s <?php if($this->tags): ?>9 j0 n3 k$ ~, a* R
<span class="post-tags">
8 M9 Z, p* H8 x9 d <?php $this->tags(', ', true, 'none'); ?>
: r) F4 q9 \) r! z. Y </span>
! O" O7 L; K5 B9 Z5 O0 Y# E7 |2 ? <?php endif; ?>. |9 k6 \" L3 j, @2 z7 Y
</div>; Q0 f6 N; U" P" c& Y8 S8 l" E% x
<div class="post-content">! g l4 y) b4 Q5 Y: _8 Q
<?php $this->content('Read more »'); ?>" ]9 y: X# o" O" K/ N
</div>
4 P( M2 T, \- Q. Y </div># h0 W- S5 N' z5 s+ Q
</div># a+ ~/ t' W' b* q/ _' U4 A; m
<?php endwhile; ?>/ W: |& k$ b" u: J# a; M0 \( O6 U8 U+ g
</div>! I+ ?, _3 V6 D, \
</div> c' v- j# h$ l( C6 G
<?php $this->need('footer.php'); ?> y7 s/ {! S- j, X
9.调整其他可能需要的文件和代码
0 E2 F8 {% J: n4 @, `( a( k5 o
5 \ B& Z" V# ]& R2 a9 v( ]0 w根据 Typecho 的特点,需要调整主题中的一些文件和代码。例如,需要将 header.php 中的 <title> 标签改为:
" m9 R/ g8 H \5 q: `2 p
6 D' g" K0 Y3 ^3 ehtml/ J- z/ ^7 X# b+ F6 S1 G
<title><?php $this->archiveTitle(array(0 ?9 o s H7 m1 o, B4 @
'category' => _t('%s'),
6 f( i. P1 V! k! y3 M. f! n9 d 'search' => _t('Search "%s"'),
5 M( I( X( Q+ g- R5 \0 h3 v 'tag' => _t('Tag "%s"'),# g! t, v' y4 f: u+ t8 r
'author' => _t('Author "%s"'),
' V2 f: }. h% L. h6 A 'date' => _t('Archive "%s"'),
5 x- C6 `7 Y) C# ^6 V+ v5 r9 R 'default' => ''+ g% E/ d9 ~, _. Z4 `' ^+ }
), '', ' - '); ?><?php $this->options->title(); ?>5 m/ e$ v8 H9 w; Y' |
</title>
/ ^1 v' c3 c: Q, K4 |7 |10.使用主题
* } v1 E" p0 s% m7 S- y5 w& p. n* u" E& D! |
登录 Typecho 管理页面,选择外观,找到 Heropress Pro 主题,并选择该主题即可。6 F/ q% y* L" r6 a* E( L
" J# o+ p0 K* O% N, t: o以上就是将 Heropress Pro 主题转换成 Typecho 主题的具体过程,希望对你有所帮助。
. |1 T4 f; S5 f5 Q x1 r. g
" a2 F1 G* ]$ {6 L |
|