菜鸟站长
个人博客主题模板、应用插件、功能开发技术资源聚合分享网站

typecho主题的页眉header部分常用代码

发布者:菜鸟站长  发布日期:2025-05-22  更新日期:2025-05-22  人气指数:8

网站页眉(Header)是网页顶部固定区域,包含网站核心 导航 和品牌标识,通常由Logo、主 导航 菜单、搜索框、实用工具(如登录/注册、购物车)和联系方式等组成。其特点是保持全站一致性、固定显示、响应式设计并强化品牌形象,设计需简洁明了、突出重要功能、符合整体风格并考虑加载速度和移动端体验,直接影响用户导航效率和整体体验。

这一部分的外在展现虽然并不起眼,但实际开发主题中所需的精力投入往往是最大的,博主经常在处理完header模块之后,就感觉难以为继,-\_-!!!太耗时间精力了。

网站名称与logo

第一句的 if 判断是判断模板是否通过模板设置设置了 logo 的地址,如果设置了就显示 logo 图片 ,否则就显示博客标题。 <?php $this->options->siteUrl(); ?> 是网站地址, <?php $this->options->title() ?> 是网站名字, <?php $this->options->description() ?> 是网站描述。

<?php if ($this->options->logoUrl): ?> <a id="logo" href="<?php $this->options->siteUrl(); ?>"> <img src="<?php $this->options->logoUrl() ?>" alt="<?php $this->options->title() ?>" /> </a> <?php else: ?> <a id="logo" href="<?php $this->options->siteUrl(); ?>" ><?php $this->options->title() ?></a > <p class="description"><?php $this->options->description() ?></p> <?php endif; ?>

站内搜索

当你的文章很多很多,这个搜索就必不可少。美化搜索框不要动 form action 和 input name,action 和 name 是必须这么写的。

<form id="search" method="post" action="<?php $this->options->siteUrl(); ?>" role="search"> <label for="s" class="sr-only"><?php _e('搜索关键字'); ?></label> <input type="text" id="s" name="s" class="text" placeholder="<?php _e('输入关键字搜索'); ?>"/> <button type="submit" class="submit"><?php _e('搜索'); ?></button> </form>

页面导航

其中<?php $this->options->siteUrl(); ?>是网站地址, \Widget\Contents\Page\Rows::alloc()是获取所有页面,然后下面的 while 循环是循环输出独立页面的,其中<?php $pages->permalink(); ?>是独立页面的 超链接<?php $pages->title(); ?>是独立页面的标题。

<nav id="nav-menu" class="clearfix" role="navigation"> <a<?php if ($this->is('index')): ?> class="current"<?php endif; ?> href="<?php $this->options->siteUrl(); ?>"><?php _e('首页'); ?></a> <?php \Widget\Contents\Page\Rows::alloc()->to($pages); ?> <?php while ($pages->next()): ?> <a<?php if ($this->is('page', $pages->slug)): ?> class="current"<?php endif; ?> href="<?php $pages->permalink(); ?>" title="<?php $pages->title(); ?>"><?php $pages->title(); ?></a> <?php endwhile; ?> </nav>

登录与注册

前台登录

<form action="<?php $this->options->loginAction()?>" method="post" name="login" rold="form"> <input type="hidden" name="referer" value="<?php $this->options->siteUrl(); ?>"> <input type="text" name="name" autocomplete="username" placeholder="请输入用户名" required/> <input type="password" name="password" autocomplete="current-password" placeholder="请输入密码" required/> <button type="submit">登录</button> </form>

前台注册

<form action="<?php $this->options->registerAction();?>" method="post" name="register" role="form"> <input type="hidden" name="_" value="<?php echo $this->security->getToken($this->request->getRequestUrl());?>"> 用户名<input type="text" name="name"> 邮箱:<input type="email" id="mail" name="mail" > <button type="submit" name="loginsubmit" value="true">注册</button> </form>
本文检索关键词:typecho教程 , 主题开发

菜鸟站长推荐教程



添加新评论 »

icon_mrgreen.pngicon_neutral.pngicon_twisted.pngicon_arrow.pngicon_eek.pngicon_smile.pngicon_confused.pngicon_cool.pngicon_evil.pngicon_biggrin.pngicon_idea.pngicon_redface.pngicon_razz.pngicon_rolleyes.pngicon_wink.pngicon_cry.pngicon_surprised.pngicon_lol.pngicon_mad.pngicon_sad.pngicon_exclaim.pngicon_question.png