找回密码
 立即注册
查看: 3245|回复: 3

可以将 speciatheme中heropress pro主题 转换成typecho的主题吗?可以详细介绍实现的

[复制链接]

343

主题

551

回帖

3619

积分

管理员

积分
3619
QQ
发表于 2023-5-23 16:51:04 | 显示全部楼层 |阅读模式
& v! [# q) i5 M5 V4 I; ^
可以将 SpeciaTheme 中 Heropress Pro 主题转换成 Typecho 主题,下面是具体的实现过程:. |3 m" k* K' s3 L( `9 M

  z0 J0 x1 t$ `( `1.下载主题文件
  C# i5 j0 n6 l9 \; E4 [/ {  L# S* [, O/ N8 x" }  J  d+ t# a) V. R
在 SpeciaTheme 网站购买 Heropress Pro 主题后,从下载链接中下载主题文件压缩包。
" P+ p: r% t9 f1 K' w  ]# G8 P& w
5 ?' F. u$ W( r# f# a2.创建 Typecho 主题目录+ d9 E! ?" F2 R" W
1 D. z6 k( L7 {# @
在 Typecho 根目录下的 usr/themes 目录中新建一个名为 heropress-pro 的文件夹,这将是新的主题目录。
) `% O! X/ e6 S% n- p6 A$ L+ ?# z* Y( J+ E( e7 [
3.解压主题文件
. u* M) I- S$ b& u" i' q* T$ a! L" w0 K& K5 ]
将下载的 Heropress Pro 主题文件压缩包解压缩,然后复制文件到 heropress-pro 目录中。应该会有以下文件和目录:
" K6 d" T6 V3 s+ o, d: V6 x& {2 s/ K; R. I4 z5 w$ z
assets/
& H: M0 J1 V/ O$ m: Ndist/
( D& ?2 [+ z9 r0 U, hinc/
7 c, ]. V7 S  A# A5 D# ~7 Cnode_modules/
2 m/ U+ Y. S/ H/ ]8 A/ `partials/, I1 N( l/ ^! u1 G7 h5 B& d
templates/
% M) p4 Z* O  U+ s  e. m.babelrc
% L: k: o6 b; }4 [# @, E- }2 q.eslintrc.js
' r2 z" h, o- \1 ?gulpfile.js& d, \; K& f; J3 i: L$ K  _$ _$ J, q: B
package.json8 t4 B( S3 M5 m( E7 K( R
webpack.config.js
6 y* G' X- u  X5 b0 b3 k4.修改主题样式表文件/ Q# R8 m0 ?+ j$ Z/ j# o; h8 ?
6 A2 N1 N. S$ N) V  m  N6 A8 D
修改主题样式表文件 assets/css/style.css,将其中所有图片、字体等路径都指向 Typecho 主题所在的地址。例如:2 S( G: @* p. E

8 n; O8 F4 Z0 g7 h$ ~0 F( A# ?css
7 Z# x" Z* j4 Z6 A5 W$ b0 Tbackground-image: url('https://example.com/usr/themes/heropress-pro/assets/images/bg.jpg');
  |& a: Y' ^! k1 M( w* B% n修改为:
' |0 I8 o) w; Q/ k7 A! i6 Q9 }( K/ o6 @
css
9 z1 k, _, r) M8 g& U+ `( Vbackground-image: url('/usr/themes/heropress-pro/assets/images/bg.jpg');* l  ~: D' o% B0 K
5.创建 Typecho 主题配置文件
. S$ V' F/ |$ V. b$ Y( X2 C8 L2 s9 ^8 w/ T! E7 Q$ n- L$ n0 P
在主题目录中创建一个名为 config.inc.php 的文件,并添加以下代码:- L0 a) P( i6 h/ m  l0 q
) P4 m2 n( ^) L% j
php# b. \! H1 R9 R$ a5 N1 t8 D
<?php' O6 @9 `  d  H7 U& ~: [7 O6 @5 a6 Y
return array(9 T" O/ a6 i! G; k4 j* D7 }; p/ J+ I
  'name' => 'Heropress Pro'," M1 Q. _, Z  d2 J( l
  'description' => 'Typecho adaptation of Heropress Pro theme',
: c/ c, r( O% l" v. ?& E3 d  'version' => '1.0',3 ]( Y/ F3 {; @
  'author' =>'Your Name',
- |0 n  A7 f6 t% l7 ~);
/ G  I& s7 U; D6 l' q6.配置主题布局文件6 d+ U# d, h, ~2 J
. m! |7 j3 [' W+ Q3 v2 I6 V
在 heropress-pro 目录中创建一个名为 index.php 的文件,并添加以下代码:
4 J- @/ c  k6 @' e8 e+ e( ]( [9 C9 Q4 U0 T
php1 k& s( G2 h; `1 h$ O  W
<?php while ($this->next()): ?>9 j9 H( W! o5 K( j8 ]5 T* d0 C
<div class="post"># v0 Y0 |2 }  p) A8 o
    <h2 class="post-title">3 w" x+ ]$ X8 [
        <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>  }# |" |$ v& M) W' M4 `
    </h2>) ]- w- S9 v. l3 T6 Z  P
    <div class="post-meta">1 L2 _6 R1 D2 h( U6 F
        <span><?php $this->date('F j, Y'); ?></span>
; W4 I8 X4 ]& H        <?php if($this->tags): ?>
7 X8 T0 V# l+ r3 o9 @# D9 L        <span class="post-tags">, S2 F$ m. j" X% {
           <?php $this->tags(', ', true, 'none'); ?>
8 }* z1 [2 z* R        </span>
" }2 n& d9 Y. L* b! _        <?php endif; ?>
. I; q! W' o+ }3 W    </div>/ B: a: ~' w9 n5 L7 E5 P9 {8 D
    <div class="post-content">+ w5 y0 d: n5 ~  E6 e7 G
        <?php $this->content('Read more »'); ?>& q9 ]0 U; _- H5 E7 f" v1 S
    </div>
4 P& W! q2 N( L4 K& p; a. q& n</div>& j3 L* S  ?3 v9 j! D
<?php endwhile; ?>+ t( S+ d+ c1 K* y& l$ `7 S
7.调用 Typecho 函数) }7 N. b, j3 f2 M! y

, y# Y2 U2 Y$ g: x# T& J在 index.php 文件中,将需要显示文章的地方改为 Typecho 的函数。例如:/ C* U* n) b) i# p& @/ f4 _  L
* p' r  j" o% J1 s9 [
用 the_title() 替换 get_the_title()。* i7 w( |, K9 {, A3 b4 _" ?: Q& i5 G

' b3 ]1 A- w9 H% g用 the_permalink() 替换 get_permalink()。
3 b! k) n9 P7 G( u4 K( K
: E9 N2 Q% z, D2 C8 f( n用 $this->date('F j, Y'); 替换 the_time('F j, Y')。& K8 V' A7 Z; O

; r# h8 p6 X+ s: M- i用 $this->content('Read more »'); 替换 the_content('Read more »')。2 G: z# V/ I2 g9 j+ ^
- N  ]( O+ L1 S6 K) H' J
8.添加 Typecho 标记
1 z- H5 Y; p+ a; d* B; G' H* j% r$ N1 w9 F
在 index.php 文件中,添加 Typecho 的头部和页面循环,以及必要的 js 和 css 文件:
6 F5 Q- [4 t0 Y. }5 m
! B2 `2 u! G* {* j. U8 g, pphp
0 K8 T: M) x7 ~+ C& M7 u. `<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>8 u2 M  E+ `+ H, `2 b" z6 c
<?php $this->need('header.php'); ?>
+ ?5 f3 g* y9 }& p<div id="main" class="container">; L7 D( ]4 K- s* q# o, X
    <div id="content" class="row">; a9 R1 k' F( `  m) B1 p
        <?php while ($this->next()): ?>
" n9 W+ w6 Y* d! R4 k6 O$ q  S        <div class="col-md-8 col-md-offset-2">
. i4 Q7 p) x. @+ O& r3 k/ w            <div class="post">
/ `: |, t1 w' R7 \* i+ `6 U( z+ j                <h2 class="post-title">& t: P, _$ r" c5 ~6 G
                    <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a># z8 v) C  {( ^2 ]' f+ \+ L9 B
                </h2>5 T* r: G, H! [: c/ G  u5 h
                <div class="post-meta">
5 u8 }# i- |, p  ~                    <span><?php $this->date('F j, Y'); ?></span>
% g% H) w6 X0 A( _6 z* J4 m                    <?php if($this->tags): ?>
' k, G, F+ U# h! C- ?3 x                    <span class="post-tags">
5 z8 ]! O+ ?5 `% ^                       <?php $this->tags(', ', true, 'none'); ?>
% ~7 v, R" u/ l! n$ r; g                    </span>
- O) |7 V; W3 E+ X8 t                    <?php endif; ?>
/ \/ y7 b1 S  z: K/ X/ b9 f$ b                </div>
3 l5 @# T; Q# B" v- r' f                <div class="post-content">
' |% K$ ]) h5 {% D7 [: T                    <?php $this->content('Read more »'); ?>9 V0 a! _( l! _  _
                </div>" d$ N2 K8 Z! ^
            </div>
5 ?2 K8 `, Y+ ?0 z% K3 V        </div>
; Z# h5 J; f1 g9 E, E6 W        <?php endwhile; ?>
: I, c4 w- L; y) h- r' x1 D    </div>+ D3 a$ P* y* ^9 L+ a, T: ^1 T9 K  }
</div>
% }# n9 x( ?5 R8 s! p& ?<?php $this->need('footer.php'); ?>
7 r# O# d6 D; k+ N" D; j8 @/ k! |* F9.调整其他可能需要的文件和代码
- K2 u# F+ y7 i+ g* ~; D/ r2 |# s; C4 i
根据 Typecho 的特点,需要调整主题中的一些文件和代码。例如,需要将 header.php 中的 <title> 标签改为:* G' T% ?% O$ Q9 {/ T
% q: U5 t, B# }4 K
html3 p5 T: }2 r+ D
<title><?php $this->archiveTitle(array(
* R7 x2 V  Z2 u( G! S        'category'  =>  _t('%s'),
, C# R0 F8 t. a1 S& I3 l! c5 D        'search'    =>  _t('Search "%s"'),
, y! y; ?& i" J. m; J7 L        'tag'       =>  _t('Tag "%s"'),, k4 p% ^0 {# s5 X/ Y# V8 N
        'author'    =>  _t('Author "%s"'),
) _4 J: W9 C! o: n2 e! r        'date'      =>  _t('Archive "%s"'),- l  {" f) X$ x* F2 A& U) M" n
        'default'   =>  ''
% t7 @# }) c- w5 J2 V    ), '', ' - '); ?><?php $this->options->title(); ?># A% I) v0 O9 k% R6 g* G8 c# v
</title>0 Q4 f9 ^& \6 X" ~4 v' D9 _
10.使用主题8 _: c, W9 D% j( }9 e

  A+ w4 P9 r1 W+ }3 c5 _6 `登录 Typecho 管理页面,选择外观,找到 Heropress Pro 主题,并选择该主题即可。5 D; s! P6 ~4 x( S4 G0 T

" i# G) w  B# Y& W8 z以上就是将 Heropress Pro 主题转换成 Typecho 主题的具体过程,希望对你有所帮助。
; I! ~) F, Y, Q- F1 o8 e* `8 t9 {2 b+ g8 k
回复

使用道具 举报

343

主题

551

回帖

3619

积分

管理员

积分
3619
QQ
 楼主| 发表于 2023-5-23 16:51:51 | 显示全部楼层
可以展示上面提到的index.php和相关的配置文件的完整代码吗?
! b6 O$ o9 z, U2 ]0 L( S
( l, ^6 D9 ~2 L8 Q  ~当然,请见下文:
7 Q3 n  G# S( i7 P6 C
5 M* m+ H, c  \, }- {  W! P* Tindex.php1 j2 E% i# m( e0 Q' l- a
- ]7 p  ^; ^9 P$ \2 _- M  u: M" K
html; J3 m) v, |" H7 I# v
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
# r5 b$ O. F# S' \  |9 l<?php $this->need('header.php'); ?>: R% ]5 m2 \: ]0 z, t, ]4 X
<div id="main" class="container">
: ~# K; N: h& j% E7 L2 o  <div id="content" class="row">5 |) Q" Y# v5 A5 _, G2 D% N
    <?php while ($this->next()): ?>
/ p8 r0 p, H! m- h  K      <div class="col-md-8 col-md-offset-2">
. J3 Z1 M- {3 E8 W' E        <div class="post">+ Y  E# N" ~; D6 d0 c& v. v* ?% |
          <h2 class="post-title">
& R' s" E0 |  U. a. u1 w            <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>3 b1 e- Y2 S$ P! W, q9 J2 U
          </h2>
( {! L+ F* B7 C" a9 i          <div class="post-meta">, i) w; r- V" F4 c: d, v4 B
            <span><?php $this->date('F j, Y'); ?></span>* K8 o! I/ _7 Z6 F" r  ^
            <?php if($this->tags): ?>
' H: W( @, h) m/ M8 ?  Q            <span class="post-tags">8 h$ D, c% o' c' a# F* t- Q- {
              <?php $this->tags(', ', true, 'none'); ?>
9 ^2 e0 C! R9 C2 i6 f+ Z$ W3 C            </span>0 K0 |' ?9 ^5 s% u* z
            <?php endif; ?>  g! d8 k2 l6 G5 l# w; P- k' A
          </div>3 T( m9 `  i: n, [9 ^3 s' q# `
          <div class="post-content">
$ ^; o, c% q5 d5 u5 y/ e' b3 M. `$ B; ~            <?php $this->content('Read more &raquo;'); ?>% B& ^: t6 `( |1 V9 X& C
          </div>% }. x, V4 I& e6 Z
        </div>, j0 w! P" ~1 ^
      </div>; J8 e+ ]& C! p4 a- T" P
    <?php endwhile; ?>6 R/ n3 `% [- U
  </div>
2 c6 Z1 W' S, e' x; w' e& l0 W</div>; A& S( p$ D, {  N  `0 [. _
<?php $this->need('footer.php'); ?>
4 R# L4 M% V# \/ k6 pconfig.inc.php
9 o9 ]9 o! @4 b, S# v/ T
; ~: x; L; G! Y+ s# m+ dphp$ v/ H' b8 C6 d
<?php
2 E9 N& R/ O: X  return array(
# R1 U* R# g* n# A; q    'name' => 'Heropress Pro',
: u$ d  H1 M0 b6 i0 e6 Y    'description' => 'Typecho adaptation of Heropress Pro theme',1 U! j* f4 I0 K6 P# c$ e
    'version' => '1.0',
! _! L; v& [7 v9 ?  W9 w- v7 y    'author' =>'Your Name',
9 w( q2 J5 `3 V% [. g$ r  );+ u$ W% R: L/ \5 l# r; b4 T: P4 ?
?>
- Z5 N  A9 D9 E- r请注意,在使用上面的代码前,您需要确保您的 Typecho 主题文件夹中包含必要的 header.php 和 footer.php 文件,并且在样式表文件中,所有图片、字体等路径都指向 Typecho 主题所在的地址。0 y( {, a3 S* w0 x$ y7 a

5 W/ }% E3 z6 t. V' M8 |希望这些代码和之前提供的步骤能够帮助您完成 Heropress Pro 主题到 Typecho 主题的转换。如有任何疑问或需要进一步的帮助,请随时联系我。
回复

使用道具 举报

343

主题

551

回帖

3619

积分

管理员

积分
3619
QQ
 楼主| 发表于 2023-5-23 16:52:31 | 显示全部楼层
上面的提到的必要的 header.php 和 footer.php 文件可以展示完整的代码吗?
8 G# k5 Q4 J) z8 G3 z0 W( C3 [( W1 E, C. W- n0 r0 L8 w
* p# h5 ^6 w) E# T4 M+ l$ w
当然,请见下文:+ q9 w+ ^" O2 Y, B9 q* S
1 ~: s, }0 E. q; x8 p+ D" i5 x% ^
header.php
& ?: {; @: t9 s6 C- t
$ M" F$ X, f6 {/ U' j: j" ghtml
4 A6 X  Q4 ^& ^3 M1 @, D8 H<!DOCTYPE html>9 I: r1 W, A$ B( F9 n8 X* A
<html lang="en">6 G$ A. w  v- u' k  M( m
<head>
+ y2 ^; \) k7 X+ U0 d. Q9 e  <meta charset="UTF-8">
9 O+ c3 N1 B. B7 z4 ]  <meta name="viewport" content="width=device-width, initial-scale=1.0">9 q2 J% I, h: K
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
2 [& v# U" @$ C# s6 N2 k' y: H  <title><?php $this->archiveTitle(array(7 U9 o  W6 f0 Z/ ~0 p5 B. ~
          'category'  =>  _t('%s'),
7 `4 B$ |- N0 J3 v; B9 K! i          'search'    =>  _t('Search "%s"'),
9 Q/ n, Z4 I9 }7 q  n- h: z) [" q          'tag'       =>  _t('Tag "%s"'),
0 I; z4 H/ f3 i          'author'    =>  _t('Author "%s"'),/ H0 x# i0 z: d9 t
          'date'      =>  _t('Archive "%s"'),
$ h9 j; f/ _6 b7 I          'default'   =>  ''
; x5 @0 O6 [; J  y      ), '', ' - '); ?><?php $this->options->title(); ?>+ c5 [5 {3 a& M8 G2 m* \
  </title>: e% P' ^1 c' }0 T: h2 N6 L4 [
  <meta name="description" content="">
" @9 t0 @4 ^. H4 V, D. w4 b  x' R, ]& m  <meta name="keywords" content="">* ?4 T9 U4 R) W' ]8 O
  <link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/style.css'); ?>">2 i9 C8 V2 e4 X- f
</head>
: X* d  d+ Q' l3 N/ H<body>
5 h7 E# @( v" `  <header id="header" class="site-header">
  y0 l, s0 h7 N9 V1 {$ d6 j9 `    <div class="container">
- G/ p% ^* ?" _8 F      <h1 class="site-title">- K5 L, S$ V0 f- x7 y
        <a href="<?php $this->options->siteUrl(); ?>"><?php $this->options->title() ?></a>
' l# i, L/ B1 \9 f3 x      </h1>6 U/ ~# U* C8 E0 R
      <nav class="site-nav">* J' w/ c8 ^* F) y+ f7 s0 ~8 j! p1 a4 ^" O
        <ul>
: {) Y4 S1 C8 c, A8 X/ g          <?php $this->widget('Widget_Metas_Category_List')->parse('<li><a href="{permalink}">{name}</a></li>'); ?>8 j; I9 U4 H& s
        </ul>1 Q' {" [* P3 @/ [
      </nav>
( {2 W6 l$ q' n8 S2 F+ r! _# Y    </div>2 j6 ~- e6 n) T. f5 ]. m
  </header>
9 |# o7 ?6 Y2 h# p1 h8 u4 ?footer.php# k* ^) _! u: H7 a9 x+ z

( S8 T) f6 J7 @& ]/ I* fhtml
' ~, r/ u! c5 Q/ n7 M<footer id="footer">
/ j+ H3 X3 a& r. \  <div class="container">
, e& a; y  Y' S9 M, p    <p>Powered by <a href="http://typecho.org/">Typecho</a> | Theme by Heropress Pro</p>
  |( t1 B3 V  @5 p2 }0 e+ U* T  </div>% n5 T! D% O& i& Z/ V& P1 k
</footer>$ t4 {8 {- h1 ~) P4 i( Q

5 K7 i5 q" ?9 e' t' m! j% E<script src="<?php $this->options->themeUrl('assets/js/index.js'); ?>"></script>- ~7 F& o0 G! C  X& x
, z7 ~+ k; [9 s: V! _& O4 @& H1 ~/ `+ T
</body>
; T' g" _% B; b! F& E" J</html>. x" W  C" d7 ^6 S) O/ U' E8 ]
请注意,上述代码中包含的路径和文件名可能需要根据您的实际情况进行修改。希望这些代码可以帮助到您。如果您还有其他问题或需要进一步的帮助,请不要犹豫,随时联系我。! O6 S/ }! b: {; ]0 s

3 P% }$ w# ?% a8 ]/ E
6 a0 _) u0 `/ r5 c/ b5 z; P# R
回复

使用道具 举报

343

主题

551

回帖

3619

积分

管理员

积分
3619
QQ
 楼主| 发表于 2023-5-23 16:53:18 | 显示全部楼层
导航菜单可以做成和speciatheme中heropress pro主题一样的吗?而且,可以实现页面滚动时菜单顶置呈现的效果。请展示出这个导航菜单实现的完整代码。/ K1 `6 r0 o4 t+ o& h- h

% [7 M. D3 e& V8 ]) \* Y当然可以,请见下面的代码实现:4 ~$ ~! `/ N7 h# D. J8 q) z) [

- \: h! v2 p% a+ Y0 ~7 b+ bheader.php
6 e3 }8 z/ x- \# Q% L
! N: I) z9 T8 T5 J2 D! chtml4 v# ]% w. @& H7 Q
<!DOCTYPE html>
: H. S4 J+ U/ s& j( n: T. {<html lang="en">, |( V  y/ L. {1 ^! c
<head>1 c3 E" _) V: h! B; \
  <meta charset="UTF-8">
: k5 j5 N9 W' {$ D  <meta name="viewport" content="width=device-width, initial-scale=1.0">
; m/ U; E  ]8 x; J4 v  <meta http-equiv="X-UA-Compatible" content="ie=edge">5 F' A7 T* l. A# j7 l0 I3 @  C
  <title><?php $this->archiveTitle(array(6 F  U/ S) w0 D- A% L7 D% W
          'category'  =>  _t('%s'),, R/ A7 A+ X' w* o( b3 v, L* m
          'search'    =>  _t('Search "%s"'),1 ]# g! F3 e6 `5 P
          'tag'       =>  _t('Tag "%s"'),- b/ b; v( g/ @3 ]% o
          'author'    =>  _t('Author "%s"'),% Y0 y/ C8 x4 o" s, H
          'date'      =>  _t('Archive "%s"'),
- o3 X. _/ y) V8 t9 }0 r. b+ L/ Q          'default'   =>  ''
8 D! {) d3 Y2 ]1 B2 w5 N8 D      ), '', ' - '); ?><?php $this->options->title(); ?>) B% ?. e" s. w( l! u; x
  </title>
4 X; L+ D  k/ E0 I1 O7 J6 ^  <meta name="description" content="">
; `& y3 C9 {/ _! q* {  <meta name="keywords" content="">+ K" b$ {/ {; T. h1 n3 c( v
  <link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/style.css'); ?>">
$ w6 R5 a2 y1 n2 `# U( d; d  <link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/navbar.css'); ?>">
  E- ^& A" e- l, j3 C5 ]9 S  <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
8 c+ [' ]3 [( u% j- u5 b; T* O% Q# |  <script src="<?php $this->options->themeUrl('assets/js/navbar.js'); ?>"></script>
0 a) T( j8 I7 A4 R% e8 G  u</head>& L- J& ~( F+ a$ C
<body>
  Y( m. w0 v/ q& _, S/ V( s  <header id="header" class="site-header"># C/ ^; c; U- R, r' L# n0 T
    <nav id="navbar" class="site-nav">
+ N2 ]+ E9 E$ v. R, r. f      <div class="container">& Q" I4 a; ]- g! k8 \
        <div class="navbar-brand">
5 g/ X; e4 c7 d; O          <a href="<?php $this->options->siteUrl(); ?>"><?php $this->options->title() ?></a>0 g; {) e$ V; t" p6 Q" S4 [" g
        </div>+ G8 k* ~$ u+ k4 A7 S5 H
        <button type="button" class="navbar-toggle">! G3 W6 `+ i/ D1 C( B
          <span class="icon-bar"></span>
+ \$ A; ?% g, o+ [1 Y4 @; U- A+ w1 r6 O          <span class="icon-bar"></span>
3 c% u- C7 l8 o: @. Q          <span class="icon-bar"></span>  E" S* B# k* m9 a7 T2 Q
        </button>* A+ ]# V$ ^- `
        <ul class="navbar-menu">  u, w9 m! A3 o9 d- J
          <?php $this->widget('Widget_Metas_Category_List')->parse('<li><a href="{permalink}">{name}</a></li>'); ?>' L7 D4 V+ J  F. G, D& j9 Y& m
        </ul>
+ ]6 ]9 F+ s1 y* U6 y      </div>
' e5 }- J3 B( d; C% H9 O    </nav>
  B* _2 H+ N8 y  </header>; p4 J$ k! J' ?2 _' [0 p& ~
navbar.css% t) v7 r1 D  l$ |+ N  C! y8 m
! Q" Y" z: h1 D& [7 }8 e
css% I. K2 s% ~! O2 ~( Z
body {
: I5 w5 T5 W) U* c$ `4 K; r  margin: 0;9 @6 [  H- k, Y6 S; S4 _* Q+ b
  padding: 0;
9 [+ q; V8 x# v" k7 r" x  box-sizing: border-box;
8 X, ?$ |4 F* b" B5 F0 \' m  font-size: 16px;( j: U4 Z: `' F9 n( R. {5 l
  line-height: 1.5;
/ d$ k+ o' F0 p& S9 B5 x  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;" X' l) ]. A  k/ u7 h
  background-color: #fff;+ o# d3 i' V1 L6 M+ E  v( ~7 z; X# H
  color: #333;! D4 {  }9 D- \& \$ [# c
  display: flex;
# O7 b4 D* X3 W5 U/ J8 H4 ?  flex-direction: column;$ Q9 z4 y% A6 M
}  d) ], P  ?' v; V" n' A

) F9 r8 v& r8 \' X& b/* Navbar */
0 j" r5 m. _7 h' g( |.site-nav {
8 T* t3 p" N! q# s' x  background-color: #fff;
: A2 A# @$ ?; Z6 |5 {# J  border-bottom: 1px solid #eee;: u' c( [: l: x1 X7 E; Z, ]
  height: 70px;% D( c9 w! G/ [" Y& |& v3 S: P/ Z: o) f
  position: fixed;
+ Y6 `+ M5 k2 ]# K  top: 0;2 m# Z! p/ Z  o& D* j
  left: 0;
1 c) R  T% N3 Q9 P: G* d4 u5 R  right: 0;
! q4 a+ m( o3 U6 C) r% d, y  z-index: 100;
6 Q; j; B, ~+ G- }! L. [}
$ t, _" [8 S* i5 E# z( ?1 I$ o5 D
.navbar-brand a {
/ j% h8 Z0 K' [  color: #333;5 t& W) L1 \/ B) J+ V0 Z, e
  font-weight: bold;
& D* t5 `$ }) j/ j7 u3 ]( w  text-decoration: none;0 Z' i4 l5 W& J! h1 P) \& d) F
  display: block;$ @6 V4 H2 W( {, ~# p
  height: 70px;
/ f' x8 [5 P3 N  line-height: 70px;
, m% P) g, g: |$ ]2 e  padding: 0 20px;3 i3 ^7 {% z0 r3 E( Z/ p
  font-size: 18px;
$ n. A5 Z' f9 R& V$ w* v6 s# H5 ~  transition: all 0.3s ease-out;
( Q' {( \; I5 e" |1 P' i}
( m% p3 ?5 i7 S5 }6 j' v7 M! H
& K) x& w' R; _, u4 g. P, r.navbar-brand a:hover {
3 \8 j0 T2 {' A- _  color: #f00;8 F7 }3 |8 `- u5 \) y% f
}
' E  I& N& Y4 z2 k6 T# v5 o9 {3 t* F# e7 Y6 I  [4 G7 |! s
.navbar-menu {
8 }, z" }% ?$ V" ^  display: flex;4 p2 r2 E2 O- f0 `7 _$ N
  margin: 0;  j; m4 x/ B' V' O% q# q* n
  list-style: none;- m) ^! ]; L. I  j) c6 \+ L  L
  height: 70px;
) y7 G; \: R" g/ y: F  margin-left: auto;
0 `" S. n- F) s6 e7 E' V}
7 T/ U  ~5 `+ {5 Z7 e' C, j* A. X# N, d
.navbar-menu li {/ P: Q$ N* t2 E+ e1 A
  height: 70px;( ?8 ~/ C7 M$ Y1 H3 b6 W
  line-height: 70px;8 h( i6 x( l; T$ G
}
* t; t8 l5 _: b" X/ r0 E+ [8 W7 a) U! O4 Z$ y9 h# j! W* Y! o
.navbar-menu li a {. B: r9 P; f7 c; e8 I
  color: #333;
, y; @- O% t  J( q; C4 k  text-decoration: none;
0 ]& W3 G  m4 t  padding: 0 20px;
7 B3 W; I7 e9 c* N$ G/ t  display: block;5 L1 q9 H" z2 q/ ^* {$ X$ |
  height: 70px;
! S% i* J" c: s( ?; `% T. e2 ?  transition: all 0.3s ease-out;
9 s- A; l+ i5 r- x# h}& L  [  G2 S/ f; U3 j6 V
. f/ b8 r6 y6 P; z2 s  C
.navbar-menu li a:hover,
/ Q( Q, W9 ^- y5 y) G9 J.navbar-menu li.active a {
4 Z8 {, O, E# G; Q& X7 k# K  color: #f00;
2 p8 f7 E) s) X- U}3 K& N4 P2 s5 Z# ^& r  z0 y

0 Y1 G7 R% D( w  d6 _/* Navbar toggle button */
# S# S; b  p: Z$ O1 W) R8 L- h.navbar-toggle {8 w! f( u: j0 c
  border: none;
$ y2 l( }  ?( a# J; V  background-color: transparent;# h# d" E. G& e; j
  cursor: pointer;. @! L  [! Y4 j, g3 t7 {
  position: absolute;3 e" h7 P. m9 P) s
  right: 20px;
1 N& V8 o/ I! F+ ?8 ?  top: 15px;9 y/ n* Y$ B" I
  z-index: 101;
8 R' s( z1 P( Q  D9 g  display: none;
# Z5 t& v- L0 y& ]2 q}
' p* P2 y! N: ?. v3 H% v8 Z3 ^" ]! k% N/ W
.navbar-toggle span {  z8 h7 W! d8 E7 E7 N! j+ s6 r
  display: block;; _9 z6 [4 t; P
  width: 24px;  q1 l% ]- D) o7 S% A
  height: 3px;: ?$ t5 O  _. [: V( S$ i6 Y- ?( Y5 Z) R
  margin-bottom: 5px;2 y  S) G" c- s% s
  background-color: #333;! Z, ?- |/ t% d8 O/ S
  border-radius: 2px;
8 |" l8 {+ D- H9 G) @}
$ K/ s0 `9 T& h8 Q- V8 A! Y" I% f( H5 k( s5 ?# d3 X
@media (max-width: 768px) {
  G! y' _) F# ?  .navbar-toggle {
% ]3 O: Y$ x7 E+ m    display: block;
5 ^' f1 W/ v; E2 Y7 p3 u: c  }6 d& m- Z0 u: t' L
  0 }2 P7 v2 U, ^" l
  .navbar-menu {2 V( v* `' b: W% c; q# u6 X- M3 T8 m! ~
    display: none;/ @0 W" \& I6 G( \6 Y0 E
    width: 100%;
+ ^5 m  ^) y1 H0 J% V/ B0 E    flex-direction: column;
$ K/ t5 i, G  D! q+ L( G    margin-top: 70px;. S, w0 V) L) {9 w+ o
    background-color: #fff;
5 y1 V( {' l2 g8 g% x. [    position: absolute;
% I: C7 x# Y: [; N# F0 y, t    top: 0;
& I) A- g9 X3 Z  v- Q    left: 0;$ Q  j0 y0 k4 c% M* W" t3 [
    z-index: 100;+ i7 |8 N) V2 w$ o; n' R
  }
  r' C' j: }+ _, m" ?' C6 u* L- ]! d/ n
  .navbar-menu li {
8 L1 _9 f% U5 P0 |" N+ r    border-bottom: 1px solid #eee;6 ]3 g. ~+ i0 A# S: K" }
  }0 q+ m/ Y( ^9 R. A% N
}% X% m$ \- @. E3 `5 _8 V
navbar.js
5 T* N- m% I/ |1 G8 h) ]: `2 b7 F  t) R1 B( V4 _
js) w' w8 B- A( s. c9 n  }' z
$(document).ready(function() {
6 c) V" V( |( t; d3 c  $('.navbar-toggle').click(function() {
- D0 \$ {. L( f+ _( R: F9 U+ ~    $('.navbar-menu').slideToggle();
5 u( e) o* F; A# w6 ?  });
3 H- a5 w& Y3 O3 s! c+ C- c
0 \! J& e* N. N* ^) U6 g  $(window).scroll(function() {
, f0 A( R/ y' v0 @& ^    if ($(this).scrollTop() > 70) {
7 K5 y+ H: p- y, n/ n1 _      $('#navbar').addClass('fixed');8 {) a2 |2 ]' ]" o
    } else {: Y# h0 b1 Y/ h$ M0 ~  s+ G
      $('#navbar').removeClass('fixed');
" Q: T" ]' l$ z) K+ b    }. h- b# y  o" ?# w) W6 H! e+ c0 U# O
  });
' q9 A3 ]  _+ l' Y* `0 L});
' s& T! E+ Z/ S上述代码实现了一个类似于 Heropress Pro 主题中导航菜单的效果,且当页面滚动时,导航菜单顶置呈现。需要注意的是,代码中的路径和文件名可能需要根据您的实际情况进行修改。希望这些代码能够帮助到您。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|通达创业无忧 ( 粤ICP备2023021749号|粤公网安备 44030402006137号 )

GMT+8, 2026-1-31 21:07 , Processed in 0.046288 second(s), 2 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表