WordPress建站教程:给网站添加设为首页和加入收藏的功能

前端之家收集整理的这篇文章主要介绍了WordPress建站教程:给网站添加设为首页和加入收藏的功能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在使用的时候,有时我们想给网站添加设为首页和加入收藏的功能,这样可以方便用户下次更加方便的访问自己的网站。

我们先来看一下效果效果如下图所示:

home

下面我们介绍一下方法

1. 切换到主题目录,打开header.PHP文件添加如下代码

Crayon-5c891d2275861591065780" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d2275861591065780-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d2275861591065780-2">2
Crayon-num" data-line="Crayon-5c891d2275861591065780-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d2275861591065780-4">4
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d2275861591065780-1">Crayon-o"><Crayon-e">div Crayon-v">idCrayon-o">=Crayon-s">"links"
Crayon-line Crayon-striped-line" id="Crayon-5c891d2275861591065780-2">Crayon-h"> Crayon-o"><Crayon-i">aCrayon-h"> Crayon-v">hrefCrayon-o">=Crayon-s">"javascript:void(0);"Crayon-h"> Crayon-v">idCrayon-o">=Crayon-s">"addHomePage"设为首页Crayon-o"><Crayon-o">/Crayon-v">aCrayon-h"> Crayon-o">|
Crayon-line" id="Crayon-5c891d2275861591065780-3">Crayon-h"> Crayon-o"><Crayon-i">aCrayon-h"> Crayon-v">hrefCrayon-o">=Crayon-s">"javascript:void(0);"Crayon-h"> Crayon-v">idCrayon-o">=Crayon-s">"favorites"加入收藏Crayon-o"><Crayon-o">/Crayon-v">aCrayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d2275861591065780-4">Crayon-o"><Crayon-o">/Crayon-v">div

2. 新建template.js文件添加如下代码

Crayon-5c891d227586b296727625" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">JavaScript
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d227586b296727625-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586b296727625-2">2
Crayon-num" data-line="Crayon-5c891d227586b296727625-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586b296727625-4">4
Crayon-num" data-line="Crayon-5c891d227586b296727625-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586b296727625-6">6
Crayon-num" data-line="Crayon-5c891d227586b296727625-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586b296727625-8">8
Crayon-num" data-line="Crayon-5c891d227586b296727625-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586b296727625-10">10
Crayon-num" data-line="Crayon-5c891d227586b296727625-11">11
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586b296727625-12">12
Crayon-num" data-line="Crayon-5c891d227586b296727625-13">13
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586b296727625-14">14
Crayon-num" data-line="Crayon-5c891d227586b296727625-15">15
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586b296727625-16">16
Crayon-num" data-line="Crayon-5c891d227586b296727625-17">17
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586b296727625-18">18
Crayon-num" data-line="Crayon-5c891d227586b296727625-19">19
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586b296727625-20">20
Crayon-num" data-line="Crayon-5c891d227586b296727625-21">21
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d227586b296727625-1">Crayon-sy">$Crayon-v">jCrayon-o">=Crayon-v">jQueryCrayon-sy">.Crayon-e">noConflictCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586b296727625-2">Crayon-sy">$Crayon-e">jCrayon-sy">(Crayon-r">documentCrayon-sy">)Crayon-sy">.Crayon-e">readyCrayon-sy">(Crayon-t">functionCrayon-sy">(Crayon-sy">)Crayon-sy">{
Crayon-line" id="Crayon-5c891d227586b296727625-3">
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586b296727625-4">Crayon-h"> Crayon-sy">$Crayon-e">jCrayon-sy">(Crayon-s">"#favorites"Crayon-sy">)Crayon-sy">.Crayon-e">clickCrayon-sy">(Crayon-t">functionCrayon-sy">(Crayon-sy">)Crayon-sy">{
Crayon-line" id="Crayon-5c891d227586b296727625-5">Crayon-h"> Crayon-t">varCrayon-h"> Crayon-v">ctrlCrayon-o">=Crayon-sy">(Crayon-v">navigatorCrayon-sy">.Crayon-v">userAgentCrayon-sy">.Crayon-e">toLowerCaseCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-sy">.Crayon-e">indexOfCrayon-sy">(Crayon-s">'mac'Crayon-sy">)Crayon-o">!=Crayon-o">-Crayon-cn">1Crayon-sy">?Crayon-s">'Command/Cmd'Crayon-o">:Crayon-h"> Crayon-s">'CTRL'Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586b296727625-6">Crayon-h"> Crayon-st">ifCrayon-sy">(Crayon-v">documentCrayon-sy">.Crayon-v">allCrayon-sy">)Crayon-sy">{
Crayon-line" id="Crayon-5c891d227586b296727625-7">Crayon-h"> Crayon-v">windowCrayon-sy">.Crayon-v">externalCrayon-sy">.Crayon-e">addFavoriteCrayon-sy">(Crayon-s">'http://example.com'Crayon-sy">,Crayon-h"> Crayon-s">'网站名字'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586b296727625-8">Crayon-h"> Crayon-sy">}Crayon-st">elseCrayon-sy">{Crayon-h">
Crayon-line" id="Crayon-5c891d227586b296727625-9">Crayon-h"> Crayon-r">alertCrayon-sy">(Crayon-s">'加入收藏夹失败,您可以通过快捷键'Crayon-h"> Crayon-o">+Crayon-h"> Crayon-v">ctrlCrayon-h"> Crayon-o">+Crayon-h"> Crayon-s">' + D 加入到收藏夹'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586b296727625-10">Crayon-h"> Crayon-sy">}
Crayon-line" id="Crayon-5c891d227586b296727625-11">Crayon-h"> Crayon-sy">}Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586b296727625-12">Crayon-h"> Crayon-sy">$Crayon-e">jCrayon-sy">(Crayon-s">"#addHomePage"Crayon-sy">)Crayon-sy">.Crayon-e">clickCrayon-sy">(Crayon-t">functionCrayon-h"> Crayon-sy">(Crayon-sy">)Crayon-sy">{
Crayon-line" id="Crayon-5c891d227586b296727625-13">Crayon-h"> Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-v">documentCrayon-sy">.Crayon-v">allCrayon-sy">)Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586b296727625-14">Crayon-h"> Crayon-v">documentCrayon-sy">.Crayon-v">bodyCrayon-sy">.Crayon-v">styleCrayon-sy">.Crayon-e ">behaviorCrayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'url(#default#homepage)'Crayon-sy">;Crayon-h">
Crayon-line" id="Crayon-5c891d227586b296727625-15">Crayon-h"> Crayon-v">documentCrayon-sy">.Crayon-v">bodyCrayon-sy">.Crayon-e">setHomePageCrayon-sy">(Crayon-v">documentCrayon-sy">.Crayon-v">URLCrayon-sy">)Crayon-sy">;Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586b296727625-16">Crayon-h"> Crayon-sy">}Crayon-st">elseCrayon-sy">{
Crayon-line" id="Crayon-5c891d227586b296727625-17">Crayon-h"> Crayon-r">alertCrayon-sy">(Crayon-s">"设置首页失败,请手动设置!"Crayon-sy">)Crayon-sy">;Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586b296727625-18">Crayon-h"> Crayon-sy">}
Crayon-line" id="Crayon-5c891d227586b296727625-19">Crayon-h"> Crayon-sy">}Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586b296727625-20">Crayon-h">
Crayon-line" id="Crayon-5c891d227586b296727625-21">Crayon-sy">}Crayon-sy">)Crayon-sy">;

3. 添加一些样式

Crayon-5c891d227586d496674957" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">CSS
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d227586d496674957-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586d496674957-2">2
Crayon-num" data-line="Crayon-5c891d227586d496674957-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586d496674957-4">4
Crayon-num" data-line="Crayon-5c891d227586d496674957-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d227586d496674957-6">6
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d227586d496674957-1">Crayon-k ">#links a,#links a:visitedCrayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586d496674957-2">Crayon-h"> Crayon-e ">colorCrayon-sy">:Crayon-i ">#743399Crayon-sy">;
Crayon-line" id="Crayon-5c891d227586d496674957-3">Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586d496674957-4">Crayon-k ">#links a:hoverCrayon-sy">{
Crayon-line" id="Crayon-5c891d227586d496674957-5">Crayon-h"> Crayon-e ">colorCrayon-sy">:Crayon-i ">#ff4b33Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d227586d496674957-6">Crayon-sy">}

猜你在找的wordpress相关文章