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

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

[复制链接]

340

主题

530

回帖

3542

积分

管理员

积分
3542
QQ
发表于 2023-5-23 16:51:04 | 显示全部楼层 |阅读模式

) @, [0 Y$ f( M8 l& o- q; J! f可以将 SpeciaTheme 中 Heropress Pro 主题转换成 Typecho 主题,下面是具体的实现过程:! n" ]. P7 o6 u4 ~! w
1 j6 A* G6 I" z- X
1.下载主题文件
- n  N7 }7 H9 [* o- G" s, }
$ c1 X& P/ q6 }) `5 o在 SpeciaTheme 网站购买 Heropress Pro 主题后,从下载链接中下载主题文件压缩包。
6 x& T5 J8 r( m+ L8 B1 ^" m& k9 [4 K0 l6 H
2.创建 Typecho 主题目录9 f6 ]5 q( I% T9 D8 s  ^

, i( L7 e; m3 y. s, `/ v; T在 Typecho 根目录下的 usr/themes 目录中新建一个名为 heropress-pro 的文件夹,这将是新的主题目录。
4 p  w/ W1 R6 K7 O4 C! x  S! E7 A4 y! w6 B4 t( [
3.解压主题文件/ r- F6 M* ^" \1 P0 k) h/ o

( U8 Y& W8 `) ^+ [! V* L# M' T将下载的 Heropress Pro 主题文件压缩包解压缩,然后复制文件到 heropress-pro 目录中。应该会有以下文件和目录:
$ L- {* A9 Z, B; c% P! P; {) C& j# ?5 r1 m0 X* W7 N* A3 {+ ^
assets/2 s6 e+ n: j6 m  T4 d: m  ^
dist/- h; U; _% i) q$ Z+ i
inc/  S3 Y8 s- P7 c, ]
node_modules/
6 L9 _6 |- K* C1 `' ]+ Kpartials/
( f/ \' g; H" W. I4 ttemplates/* [' p0 n& s; \1 I
.babelrc1 f% a8 \! Q& S) l" n% ]: j' c# l
.eslintrc.js. z# r$ H- t$ a: R3 J, r
gulpfile.js. u6 ^# Z, v  V. I( L0 w2 O
package.json
# a! x3 e9 s3 f) S  R4 Pwebpack.config.js6 l, A" `5 Q; u
4.修改主题样式表文件: K+ U& v( t: w$ \3 ~

, w% R+ P5 y( S* v* W修改主题样式表文件 assets/css/style.css,将其中所有图片、字体等路径都指向 Typecho 主题所在的地址。例如:1 Q$ c6 L1 g4 U- O

, @) Q( }  o6 @2 W8 r' H6 \css
8 }1 R0 Q% \( gbackground-image: url('https://example.com/usr/themes/heropress-pro/assets/images/bg.jpg');% T( \' f2 L! f- c1 {
修改为:
- d% V/ R, L* |4 K" G
* u( k3 k  J0 ]: d" s7 Pcss
( d# F6 P$ i$ c  ]3 |8 m8 nbackground-image: url('/usr/themes/heropress-pro/assets/images/bg.jpg');
* a' d/ d: M8 N( `8 T$ H5.创建 Typecho 主题配置文件
$ F/ U) Z' Y1 d* L% U
) H7 Z. g% i, k9 b* E, j在主题目录中创建一个名为 config.inc.php 的文件,并添加以下代码:
# ^/ }3 v1 ?1 T( X* _7 |  N. \7 \* \" }9 O& }
php: ?' J# A# k7 f+ S9 O7 g) _3 m* e- ~
<?php; u' N/ L% k* |8 Z1 W1 c
return array(+ O; x3 g/ B; X
  'name' => 'Heropress Pro',
1 L9 Q2 ^, k% H& ]8 u+ S/ A  'description' => 'Typecho adaptation of Heropress Pro theme',
  v" ^% c8 w9 ?* D( l# e! q' _# i! B  'version' => '1.0',
0 I5 A8 ]( ]: y9 C2 R  'author' =>'Your Name',- F5 j" ]7 |5 S( [, P
);
5 _; X* }3 n- Z5 k1 i$ {6.配置主题布局文件) t7 D, N1 y  _. m6 m
  a5 D/ ?' o% G- J# l+ d  a
在 heropress-pro 目录中创建一个名为 index.php 的文件,并添加以下代码:5 a% G; T; r& n# Z
" F. ^  q) w& ^% q% e. d
php
; E' ~3 ]* |& \) p, N<?php while ($this->next()): ?>
- k" Z: E& X6 |<div class="post">
' u0 P& a$ g5 u  x& U9 S    <h2 class="post-title">
( L2 ?. C: h' W) n' C        <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>
' {. D4 E7 t- F2 B' m9 E    </h2>& y; E- I# a0 o' u& D# X) ~7 n
    <div class="post-meta">& z  D- V& w+ C+ c) ], T$ ?4 t  b
        <span><?php $this->date('F j, Y'); ?></span>+ N* A6 a3 k- q6 c# s/ {; n
        <?php if($this->tags): ?>* Z3 N$ t  j5 Q
        <span class="post-tags">
2 i  U6 N1 ~8 u7 a           <?php $this->tags(', ', true, 'none'); ?>
0 y' _$ e0 H0 ~. X9 @0 C1 h& a        </span>
) j9 F& V5 v, X: [! i6 L        <?php endif; ?>: h9 n  {. k6 @8 J- A6 P
    </div>0 M  J4 q/ l4 T
    <div class="post-content">
8 X, ?% q3 U3 T7 }5 E+ Q7 y2 J) }        <?php $this->content('Read more »'); ?>* l6 b0 Q& ]& R: L6 j9 _. S
    </div>
/ N' Y) B/ E0 @* ~# X8 K8 H* y7 N- y</div>* m3 D8 m3 p: ]" h
<?php endwhile; ?>
% }% B, l3 N0 e7 r& p, D) m7.调用 Typecho 函数' _6 D8 q4 X- `) p: w$ c

2 \! y( @3 E0 y$ X7 u在 index.php 文件中,将需要显示文章的地方改为 Typecho 的函数。例如:
0 f  r- T% [3 n: T, M
0 d; }0 K/ t, \2 L5 q1 L用 the_title() 替换 get_the_title()。
7 @: Z: ]" p( C' U+ X9 }) z+ I6 n: I4 F9 W$ p* c- O5 U9 }. O
用 the_permalink() 替换 get_permalink()。6 a; b2 f% n' H4 ]
7 m' J! n5 X5 [5 ?, L# Q$ |
用 $this->date('F j, Y'); 替换 the_time('F j, Y')。4 H, \2 R/ F, W6 ~$ N* b2 R

; O7 t, `' [+ B+ `" S用 $this->content('Read more »'); 替换 the_content('Read more »')。. K0 B4 G7 b& l# C" _
( t) P) C/ Y% l; }+ J
8.添加 Typecho 标记' _! \- z. ?. L7 K+ f0 X' j% b0 p

# B/ f/ W, l5 t! T在 index.php 文件中,添加 Typecho 的头部和页面循环,以及必要的 js 和 css 文件:
- Z5 u1 Y/ [4 P6 E
; G& y/ n5 w! z) O! dphp
2 U% n( a3 P8 W6 Q# c- f<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
+ d  [4 v9 f) ^) q, s0 D<?php $this->need('header.php'); ?>
% Y7 y( W- B' f7 O+ m9 d8 {( k% v* m. W<div id="main" class="container">* }) ?$ d( H4 \. b* s, Q
    <div id="content" class="row">
4 J7 S+ `, Z5 Y2 u3 O1 c        <?php while ($this->next()): ?>( S. R7 E) z  H0 G& T- v9 U0 q) G
        <div class="col-md-8 col-md-offset-2">
2 ?/ R/ U! Q& ~+ U1 U. n: p            <div class="post">' F3 G9 u& c+ F4 U3 c
                <h2 class="post-title">9 e7 P+ D4 k$ H. ]- }3 _
                    <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>, B% n5 N5 U$ D& w
                </h2>
. x2 y1 v3 S. Z. p                <div class="post-meta">( p! X0 e. E8 ?& `$ E4 V7 F
                    <span><?php $this->date('F j, Y'); ?></span># C9 B- f5 s- u( y
                    <?php if($this->tags): ?>
7 F4 K9 y/ x% u- |7 J                    <span class="post-tags">
9 n5 S1 S& S; `1 O$ Q8 U* f                       <?php $this->tags(', ', true, 'none'); ?>
1 l2 d! K" |+ w( V+ ~4 v                    </span>
7 S7 ^+ X; q% |4 v; O0 F) N                    <?php endif; ?>0 @4 Z( B6 s. M! A6 z
                </div>  r2 P# B6 V6 B' v5 N
                <div class="post-content">' S* P. z" B9 I; Q
                    <?php $this->content('Read more »'); ?>
: g% C* `9 d& p8 H* Y' z                </div>& F+ ^& D9 }- _
            </div>
( t1 L2 G0 D! x" Y        </div>
& N" N& p; l* |0 R8 V        <?php endwhile; ?>) X( v& l& S7 z4 S
    </div>
2 W5 [5 ~" q& B( a$ U</div>
5 g6 k; J$ x. c0 y& B: m8 p<?php $this->need('footer.php'); ?>5 F0 C5 p* w$ x* \/ u- Y5 j
9.调整其他可能需要的文件和代码  Z+ U/ f9 t, Q9 k: {

' B8 R$ l! i0 l; H" \1 v根据 Typecho 的特点,需要调整主题中的一些文件和代码。例如,需要将 header.php 中的 <title> 标签改为:
+ S4 A& E& q# W( y% S$ S! e) \* R! R: e) B& o( n# ]# M% V% {' ]
html3 K6 t+ ^# w& L
<title><?php $this->archiveTitle(array(
2 a+ T% s; K& V& [: b        'category'  =>  _t('%s'),
" T# ]. N; N4 O/ h8 D; V3 {* f        'search'    =>  _t('Search "%s"'),
/ X5 P6 K* U% k5 [% @/ u        'tag'       =>  _t('Tag "%s"'),5 W- g1 s4 p* E- @8 j* [/ F5 M
        'author'    =>  _t('Author "%s"'),4 ~! y8 b. A. }
        'date'      =>  _t('Archive "%s"'),1 m: }$ X1 G" r) p# `5 r( T- C# c
        'default'   =>  ''$ ^* J+ r  C# w/ H$ }
    ), '', ' - '); ?><?php $this->options->title(); ?>
; Y# N9 @; G* _5 T</title>9 X9 t" g% H$ J1 y% ?- P& `; |
10.使用主题
* E5 }2 C+ P: W# B( Z/ @; x. y! W" e( m. E# L' F
登录 Typecho 管理页面,选择外观,找到 Heropress Pro 主题,并选择该主题即可。% y+ s6 q" L8 z+ I3 i
+ r& `' A  r  G) |
以上就是将 Heropress Pro 主题转换成 Typecho 主题的具体过程,希望对你有所帮助。9 P0 E! }4 m2 C1 a
. m1 k+ g8 I: j9 k
回复

使用道具 举报

340

主题

530

回帖

3542

积分

管理员

积分
3542
QQ
 楼主| 发表于 2023-5-23 16:51:51 | 显示全部楼层
可以展示上面提到的index.php和相关的配置文件的完整代码吗?
( U8 ]& `& |3 d: w
, t! H) B& X1 k/ ^当然,请见下文:2 Y8 ~7 ~/ q9 X# h0 i
" @! H# K# R+ N6 @* [
index.php
" C# a. t# s; L  e8 o6 I, ]# |) U( n
html2 _+ U/ {. f% q1 K
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
. H# H3 F; D) F3 F! z* ~/ u<?php $this->need('header.php'); ?>
. Z) `) V2 k' L9 H% {<div id="main" class="container">: a7 X3 @& D) Q- O7 L9 A
  <div id="content" class="row">5 _( F2 C; U, y* E. H2 L" L
    <?php while ($this->next()): ?>! r, O: V" E1 _0 [! q. A
      <div class="col-md-8 col-md-offset-2">) D2 I6 k, a  N% `- _2 R5 E
        <div class="post">" b9 h6 j1 {+ k
          <h2 class="post-title">0 S- f& ^/ S) j6 W/ n# i; Y
            <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>
! @. l+ ~: h0 R" H9 a! p" K- X$ o          </h2>+ [% A, h: U3 A0 {
          <div class="post-meta">' w, {  d7 l% ]9 g) O
            <span><?php $this->date('F j, Y'); ?></span>) D6 {) B9 H, j9 t
            <?php if($this->tags): ?>; g; n4 m/ m% E: L, d- H( r7 F
            <span class="post-tags">
/ Z' v" ?* Q5 b2 R- a6 D              <?php $this->tags(', ', true, 'none'); ?>
& K0 R5 G7 k9 J$ _6 m4 w            </span>2 u' G5 a! i" \: O  P) M. R0 y
            <?php endif; ?>
+ W% \* S9 E2 z          </div>+ p5 @9 R' k' b* M7 {) y7 D4 ]4 x
          <div class="post-content">- l) Y! }+ T: R. u4 n% F. b9 w
            <?php $this->content('Read more &raquo;'); ?>
1 ~6 ^  _. h) f, _1 i$ X2 k          </div>( Y, A/ L$ g$ Y' }, s! {
        </div>* F- |5 ?% a" c" v# g/ V9 f; ^, d/ S
      </div>
. I* G, `: U/ s# y  e1 ]( x1 \    <?php endwhile; ?>
5 c: M! C; ]: ?# ~/ q( ?  m2 h8 `& Y  </div>2 d! F5 X# d6 D) m) A/ f
</div>
" ^1 T# x; a2 z<?php $this->need('footer.php'); ?>  K/ L+ r2 o. T
config.inc.php3 }( N: k9 [6 g9 C6 |4 @& F/ g

3 O% H* a7 s: v* Z0 O3 Yphp9 W) W' d- x! n9 K3 I7 o
<?php; `7 `6 P' @3 U$ l3 |
  return array($ ^* P/ L% x" R1 \, ^* v
    'name' => 'Heropress Pro',
; H: r* N+ N% Z" K    'description' => 'Typecho adaptation of Heropress Pro theme',
5 A1 L& w& V4 s! m. O    'version' => '1.0',9 [4 n) ~7 e) y/ a; H
    'author' =>'Your Name',
* t! W  |( z6 w  );
! t' v4 |8 D) q* \4 U?>8 S. w3 o' G& t. M6 M
请注意,在使用上面的代码前,您需要确保您的 Typecho 主题文件夹中包含必要的 header.php 和 footer.php 文件,并且在样式表文件中,所有图片、字体等路径都指向 Typecho 主题所在的地址。7 R; Q0 P% g. k$ w( W

4 k- v0 P$ A" n  H6 C5 `% y0 p希望这些代码和之前提供的步骤能够帮助您完成 Heropress Pro 主题到 Typecho 主题的转换。如有任何疑问或需要进一步的帮助,请随时联系我。
回复

使用道具 举报

340

主题

530

回帖

3542

积分

管理员

积分
3542
QQ
 楼主| 发表于 2023-5-23 16:52:31 | 显示全部楼层
上面的提到的必要的 header.php 和 footer.php 文件可以展示完整的代码吗?
0 u$ ?) g! P  }" w) t+ ~6 n. s2 G& ]5 {, p! ], Z% T  }5 e- l2 }
" F" x+ j* Y$ }" s7 ?5 ]
当然,请见下文:. I  d$ ^2 w! o
. k/ R! E5 x& {5 a& J/ S, F
header.php
2 q  Q9 }$ y& m8 p3 K: E7 J: U8 m; y+ G& X. ^( `8 Q  K
html
" B8 c! U+ M% [& ^  x: v* W: B9 p! w<!DOCTYPE html>0 s) g1 t+ q0 ]/ }# {
<html lang="en">
* _7 N6 ^( X3 L+ X/ i* O<head>
0 E! ?! Q3 D- k( J7 l9 Q1 w% t  <meta charset="UTF-8">( q$ p& C* q, u. s7 H0 q% z3 R
  <meta name="viewport" content="width=device-width, initial-scale=1.0">4 w7 z$ v1 d: g3 n& ^; x
  <meta http-equiv="X-UA-Compatible" content="ie=edge">( O& ^5 f/ r3 ^9 ^
  <title><?php $this->archiveTitle(array(
, e3 u1 F: }3 Q' m$ G4 W          'category'  =>  _t('%s'),1 s, c0 ?4 r5 }& `3 d' b0 k
          'search'    =>  _t('Search "%s"'),' \: k  |; l3 Q3 y
          'tag'       =>  _t('Tag "%s"'),
1 y$ ]( I* P) `3 F/ J5 N5 `$ [          'author'    =>  _t('Author "%s"'),/ x. F; I0 r; l8 _( q! ^8 J
          'date'      =>  _t('Archive "%s"'),
: ~, Z7 p2 J1 R. b& w          'default'   =>  '': Y. _1 @& M% H
      ), '', ' - '); ?><?php $this->options->title(); ?>+ y: M' q: c2 P& _( `( s" o
  </title>9 `, o" C7 c: r# M1 t
  <meta name="description" content="">
4 Q( x, E) m- [- V; @+ }- b/ y  <meta name="keywords" content="">7 k) T& P* ?4 y7 [& W8 [$ O: @! m
  <link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/style.css'); ?>">6 D$ v! Q) T0 X- l  X5 D0 p
</head>
  j- d' B7 G# j9 }) g9 j# Y<body>3 L$ E: F. G: c% ?/ z- c2 }' O0 _
  <header id="header" class="site-header">
6 T2 ~2 ~/ E4 ]& \. ~! G9 h2 T    <div class="container">
& u# d) u! }" X/ H) W3 E      <h1 class="site-title">8 E3 x; h% A$ G% S  f- T6 u
        <a href="<?php $this->options->siteUrl(); ?>"><?php $this->options->title() ?></a>
8 {$ x% F& f; ?% P7 R* V  Z# h7 Q      </h1>
2 x- V2 I$ d" d4 F9 I& J      <nav class="site-nav">$ s$ A3 G) N6 K2 q4 I2 T9 t
        <ul>0 h  d) [* k" c& ?; ?& m
          <?php $this->widget('Widget_Metas_Category_List')->parse('<li><a href="{permalink}">{name}</a></li>'); ?>. D/ {2 I" }. @
        </ul>
: I% S; S' P  P1 U9 d5 s      </nav>- F2 x6 C, Z2 N5 _! ^0 A1 _4 v7 p, k
    </div>6 W( |$ A! M9 B/ g- a
  </header>
+ N. f+ E: h0 A2 _9 q# Nfooter.php* ?8 [8 ?: H8 G- x4 \

2 K5 }2 j. D" W2 b' Whtml( V0 l) n9 W0 d
<footer id="footer">( |* s! Z. t/ k: x& {# B8 ~- O
  <div class="container">
5 y* o: }/ l4 L0 L    <p>Powered by <a href="http://typecho.org/">Typecho</a> | Theme by Heropress Pro</p>" c" l: u& b0 n& ]# ?& T$ |  @
  </div>1 ^8 l6 \0 T1 @# V( l% z# l
</footer>3 q  U9 H3 u! h6 @. N2 f

- ?0 E3 s3 M' Z0 w7 Z! t. }" J<script src="<?php $this->options->themeUrl('assets/js/index.js'); ?>"></script>2 d* i1 i" f. r. d6 C

, y. X; d2 q% x3 f. U, V</body>
* `9 w/ B. O3 w& {6 u</html>
' K+ J. m' g* _( i; u& n( r请注意,上述代码中包含的路径和文件名可能需要根据您的实际情况进行修改。希望这些代码可以帮助到您。如果您还有其他问题或需要进一步的帮助,请不要犹豫,随时联系我。
# P; y& ]$ N$ A& h' t1 b1 \# x8 o: r; J9 _* c
7 a6 P# N2 Q9 Z
回复

使用道具 举报

340

主题

530

回帖

3542

积分

管理员

积分
3542
QQ
 楼主| 发表于 2023-5-23 16:53:18 | 显示全部楼层
导航菜单可以做成和speciatheme中heropress pro主题一样的吗?而且,可以实现页面滚动时菜单顶置呈现的效果。请展示出这个导航菜单实现的完整代码。
3 }4 J5 i; V6 U3 D- z. v5 y( a) s' }/ @
当然可以,请见下面的代码实现:
) F3 A, S! K- F9 s: s6 u% O3 @* N- I9 u0 e3 `
header.php4 x/ _9 S' I( d" Y+ N6 y! m7 F
" c( C1 m2 K. f& l2 L- R1 E' ^
html
( r  G  U" |* o+ X( [5 h6 N<!DOCTYPE html>( {0 i! ?7 z) O, g2 d7 g
<html lang="en">3 {# {- j, g: z" W1 v
<head>- c- o6 C8 r! t8 k4 F# }" D- }
  <meta charset="UTF-8">% p9 T) i6 S- i) h1 B- \
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
) A0 _9 X. q: I  Z1 Z7 B& w+ K) Y$ o  <meta http-equiv="X-UA-Compatible" content="ie=edge">( ?  G  S8 t' |$ N
  <title><?php $this->archiveTitle(array(' v1 ]0 J% x  X
          'category'  =>  _t('%s'),
3 S" ~4 }& f% {3 _5 Z1 d  P& z$ x( W6 Z          'search'    =>  _t('Search "%s"'),6 n3 t$ H. L. f& F1 e
          'tag'       =>  _t('Tag "%s"'),
5 |  Z3 {! u: C. x! [' u! \& C          'author'    =>  _t('Author "%s"'),
4 p7 s0 A0 w  b3 W) {          'date'      =>  _t('Archive "%s"'),
+ O& d  G8 q: Q% V# j          'default'   =>  ''$ V: s& Y+ a- ~0 m0 Y! p8 b
      ), '', ' - '); ?><?php $this->options->title(); ?>
5 Q' }9 G, U$ i% }+ Q; @1 W  </title>* K( {% d  c/ ]3 h
  <meta name="description" content="">. F& R: w1 O( ~& L% Q
  <meta name="keywords" content="">2 F+ p: ]: }  W) a7 }
  <link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/style.css'); ?>">) l1 f7 _' T  O5 h* u& I
  <link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/navbar.css'); ?>">1 e( P3 h. b1 D4 H) ^* C
  <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
3 _% [% v9 O4 Q  <script src="<?php $this->options->themeUrl('assets/js/navbar.js'); ?>"></script>
$ L2 Q- R5 h3 X. m. m</head>' O1 c) c3 r- M
<body>
- Q: q  n, c' b) j& Z( F  <header id="header" class="site-header">
. |( q# ^7 R0 x( W$ M/ \0 {; J' N    <nav id="navbar" class="site-nav">
) f- ]" f! b4 P$ h3 _% j, }$ `      <div class="container">7 y( S. d9 I% _9 B  i! r
        <div class="navbar-brand">
' ~6 ]4 `* l0 ?6 m$ R) A3 Z          <a href="<?php $this->options->siteUrl(); ?>"><?php $this->options->title() ?></a>
, m8 J& i* [& r! O        </div>
) E9 E8 g. S+ o  \        <button type="button" class="navbar-toggle">9 D- x# h$ X; z0 \. Z) h. x
          <span class="icon-bar"></span>
6 h/ n8 L7 X$ G* a1 s1 U' c" p; z6 d          <span class="icon-bar"></span>
$ u; Y( R* O' P* c0 C, ]: U  Z          <span class="icon-bar"></span>
$ ]- U  L/ `% l0 @/ j; y# z        </button># W' z- E7 _4 @- O4 g9 o& a
        <ul class="navbar-menu">1 U/ t5 O( M* g2 k
          <?php $this->widget('Widget_Metas_Category_List')->parse('<li><a href="{permalink}">{name}</a></li>'); ?>
+ N5 C5 j8 G7 \, e  U/ n! S        </ul>
6 s/ P" c. v8 e& o5 E; C; g      </div>
" x9 W" @9 R+ N7 K1 W& S/ X6 X    </nav>9 E  c& G* m8 p% G
  </header>" C' V9 J6 W# r, f/ r1 s: S
navbar.css% ]/ p0 t( X6 t! H& t

7 v/ Q: ?9 X; f, y! |/ M  ^css9 I/ h/ M! U+ _8 T9 f$ I2 q
body {+ p+ I! x$ p) a( {  Q; k8 k4 R
  margin: 0;
6 }0 c! y; M5 e! H, N9 n1 ~. A  padding: 0;- w/ L) w: q* t* Y: F
  box-sizing: border-box;
5 W2 Z& [" s# y+ m2 w  font-size: 16px;) c6 l8 q& z4 F$ S: k
  line-height: 1.5;
8 n, J- M' H2 h. a4 e  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;0 L; k$ _$ |; j5 w" y5 i5 n0 y
  background-color: #fff;" H) U; A! C2 a, ~0 W
  color: #333;
  Z" p* b- l' U/ x, D  display: flex;$ F6 ^( \" K" J7 c, C
  flex-direction: column;
4 v, u  l1 D5 A. I$ R}1 X, R! ]  ]8 q' ?  L) B( }8 `

) n3 q8 C7 B8 Y5 T( e; D/* Navbar */
# g4 H% S4 q4 r.site-nav {
, m( A( H! u* E  background-color: #fff;4 M% e' G0 ^( S
  border-bottom: 1px solid #eee;* u% j9 Z4 E, M3 b* Z6 t
  height: 70px;
% Z0 B/ w( Y$ f  v0 ~: I  position: fixed;
5 k- {1 K* \. N4 u  top: 0;# V* E# `9 u& |( o+ w, Y; u4 s& g
  left: 0;, h4 `0 H1 U) w0 g1 V
  right: 0;
& M$ n/ [3 U- l8 N6 q! E  z-index: 100;
- I: d7 S. H6 U$ ?# J* d+ v}6 a5 }& l% ?% i: B# |& B+ @3 _% e
. u8 O8 I1 D  S
.navbar-brand a {
! P: x7 ?* t+ `# L" |4 ?& ~  color: #333;
0 L1 c! k* k! U  font-weight: bold;9 C; [/ _" |& m- G
  text-decoration: none;; n6 q* h4 Z) O" w4 a' v9 Y0 c
  display: block;% n0 k' T$ {  q+ ^3 k9 @
  height: 70px;; Y2 h" [9 m8 n1 Z
  line-height: 70px;1 M) n3 S1 V; O+ f# T  Q
  padding: 0 20px;
6 j# O; F# V! K# f" L1 V  font-size: 18px;
- q9 L2 z3 T5 ?5 g+ s  transition: all 0.3s ease-out;; r7 l0 i" Y  D) _
}: o& D8 Y" p3 F+ X( s6 C! t) |
4 y% B% H( P8 y# f9 `5 i; N
.navbar-brand a:hover {. B9 l! Z8 M, M+ a6 V
  color: #f00;
. z: E- ]4 D, |( q9 _5 ~/ h}: [$ O1 w$ i: f7 @6 B2 T2 W

1 V5 F! S! r; R" h% G.navbar-menu {
. o- P' C( X3 C$ ]/ Y: Z" i1 r  display: flex;
$ o( Z1 m( `- s; G# ?2 H. A  margin: 0;  R' D8 d1 {" [+ \
  list-style: none;
: S+ }/ \% Y) p0 O  height: 70px;
- g1 m  P  C: o$ b  margin-left: auto;
7 j1 o1 G* q" q# h2 M# ?1 I7 h}
, w6 N7 l' A4 O, y5 \" @- g. ^* d% v, a0 E& {) \! L( Z! E  t/ |9 n
.navbar-menu li {- y! r' H, J$ p6 C2 v2 U* N0 S
  height: 70px;
' k# e* {6 ?" e) s& t. J, U' Y  line-height: 70px;
2 V2 o% |" ]/ v/ z+ d7 n}
  t  O. h5 H2 Y, {0 X% L( |
9 Q; p; u. K- h1 p% ^4 h, H, ~.navbar-menu li a {
; m4 c* H; V$ f/ S8 F! @9 E  color: #333;
5 m+ q$ p9 n3 O+ d  text-decoration: none;2 H* O. _+ j8 `! A
  padding: 0 20px;0 K& R( ]3 e( r% c
  display: block;2 j* R% r. ]2 G' w$ W  V# V
  height: 70px;
, t- K/ Z+ s/ z  r% m: ~$ k$ P9 K4 E  transition: all 0.3s ease-out;
) r/ a! p9 A: g$ z}
. G$ S9 C( W* i# @- w/ ?. [+ p6 @1 w2 P" \; v: M+ M1 Q
.navbar-menu li a:hover,. i4 W- e$ a% d* Q% o: i
.navbar-menu li.active a {
1 Z, o4 o8 v! j  color: #f00;
, H& Q" N0 I3 d/ m" ~}* Q& I& _! K, m4 Y2 z1 ]
1 P0 b- O0 K" A4 C# C* N
/* Navbar toggle button */# z( T: ~7 `1 z7 z/ T9 Y
.navbar-toggle {* _* k7 i% h* a6 r2 u
  border: none;* c# w# t! E( a  V
  background-color: transparent;
8 \; L/ ~3 J* A) V8 u# v" I1 C+ o/ s  cursor: pointer;
5 B: `  R/ l) }  J( t! S  position: absolute;; H  T( I* o+ [8 h$ H
  right: 20px;+ U7 w3 ]( B* e: V; m) f1 X/ ]
  top: 15px;! Z' e6 x6 L: K3 e* U
  z-index: 101;1 |# X' M( T" r" ^1 T. [" s: c
  display: none;$ I. l" [4 J: w$ |4 g; q0 P
}
: @5 c8 a6 N: q) f, h8 C# v0 a/ j; m/ h; @2 {1 |
.navbar-toggle span {
$ f' B3 i. k0 C7 Q/ Z  display: block;
( N" g: n' ?, J, E1 [5 L0 }  width: 24px;
4 f( {2 d/ U* e& X  S. F; U  height: 3px;* P& }$ h; E7 {
  margin-bottom: 5px;% V2 y5 f7 s# T5 T0 B
  background-color: #333;, }8 `  i# x) |0 |
  border-radius: 2px;2 I$ d5 C3 I9 B- T, d
}
+ ~( x) W- Q8 C6 q
9 P9 z" x; s! v& l0 j( r@media (max-width: 768px) {" U. V4 j5 I# d5 d! W
  .navbar-toggle {8 c" M! F0 Y; }; f9 K2 e6 b5 j: i
    display: block;
7 _9 l( \4 \' N$ y! ^- e7 Y. z  }* G  i9 W2 B4 _$ ?5 D
  ' }1 j9 d& M* V% J* }' m
  .navbar-menu {6 ^+ z6 E! {9 }& G' h9 \  _4 L& Q
    display: none;" q6 x$ y1 u$ Z/ k4 x/ U- c9 ]1 R+ U
    width: 100%;, l" ~; F3 S6 A  H0 Z8 D& c' ?
    flex-direction: column;5 `1 `; s+ x2 q) v( i
    margin-top: 70px;/ V4 ^& E( F" |- `2 f
    background-color: #fff;. f0 z$ T$ X) Q9 o* M  f7 P
    position: absolute;
; H4 N2 Z1 i; M    top: 0;( h  ~5 z7 Z# Y) a
    left: 0;: J/ ^3 F, h4 c7 S4 Z2 _# s
    z-index: 100;
( M! N- C, v$ E1 P) A0 |; `  }! Y" j" Q$ v2 K/ d% ~

' W9 l7 @) _, [7 C& y, f; |  .navbar-menu li {; E! s" L% N" s) |$ x1 W( H0 s
    border-bottom: 1px solid #eee;; o4 V/ \& o0 X& P* c7 @( f  e
  }, X$ Z# n! i: h0 U
}, F& Y6 S( c- N% Z4 o. y( l# l
navbar.js" \& S9 e$ n' A; Q

' A8 T" H  m* r1 g5 ^( M) Vjs9 w2 h' _$ L5 P9 t  I& g7 c
$(document).ready(function() {
9 s& y4 K0 e5 N( j% W% `  $('.navbar-toggle').click(function() {
# z- i6 W$ ~5 x    $('.navbar-menu').slideToggle();4 Q# s+ [/ P* N- N) H
  });
0 j) y& @7 }4 o$ E0 |6 q, [' ^
* H/ u4 s2 b9 o1 M  $(window).scroll(function() {5 k! s0 Y% r0 _/ S* C6 s
    if ($(this).scrollTop() > 70) {9 y% u' D) C; C" Q0 [+ e5 [
      $('#navbar').addClass('fixed');5 S1 o% k8 U& c. ]: c& \9 E. o
    } else {
. l" e& I+ m5 |/ y" O. N      $('#navbar').removeClass('fixed');9 @& G0 q- T1 K- D
    }  g' K& s7 n" u: Y# Q
  });
. l" Z! ]( ?/ w! h4 z});
, C7 m$ f% x* {, L! O上述代码实现了一个类似于 Heropress Pro 主题中导航菜单的效果,且当页面滚动时,导航菜单顶置呈现。需要注意的是,代码中的路径和文件名可能需要根据您的实际情况进行修改。希望这些代码能够帮助到您。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-1-23 15:25 , Processed in 0.017775 second(s), 2 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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