WordPress建站教程:在新添加的文章前面添加NEW特殊标记

站长朋友们在使用的过程中,是否曾经遇到这样的问题:希望在新发布的(24小时内发布的)文章前面添加new这种特殊标记?这篇WordPress教程里,91wordpress就向大家介绍一下具体的操作方法。

1. 切换到主题目录,打开functions.php文件,加入以下代码:

以category.php文件输出当前分类的文章列表为例,完整的代码如下:

很抱歉,没找到您需要的内容,点此返回

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-5c891cfe4f563283568781-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-2">2
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-4">4
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-6">6
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-8">8
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-10">10
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-11">11
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-12">12
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-13">13
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-14">14
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-15">15
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-16">16
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-17">17
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-18">18
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-19">19
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-20">20
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-21">21
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-22">22
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-23">23
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-24">24
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-25">25
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-26">26
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-27">27
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-28">28
Crayon-num" data-line="Crayon-5c891cfe4f563283568781-29">29
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f563283568781-30">30
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-5c891cfe4f563283568781-1">Crayon-o"><Crayon-e">div Crayon-v">idCrayon-o">=Crayon-s">"list-all"Crayon-h"> Crayon-t">classCrayon-o">=Crayon-s">"list-all"
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-2">Crayon-h"> Crayon-ta">PHPCrayon-h">
Crayon-line" id="Crayon-5c891cfe4f563283568781-3">Crayon-h"> Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-e">have_postsCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-o">:Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-4">Crayon-h"> Crayon-st">whileCrayon-h"> Crayon-sy">(Crayon-e">have_postsCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-o">:Crayon-h"> Crayon-e">the_postCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891cfe4f563283568781-5">Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-6">Crayon-h"> Crayon-o"><Crayon-e">div Crayon-t">classCrayon-o">=Crayon-s">"one-post"
Crayon-line" id="Crayon-5c891cfe4f563283568781-7">Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-8">Crayon-h"> Crayon-o"><Crayon-e">div Crayon-t">classCrayon-o">=Crayon-s">"p-date"
Crayon-line" id="Crayon-5c891cfe4f563283568781-9">Crayon-h"> Crayon-ta">PHPCrayon-h"> Crayon-e">the_timeCrayon-sy">(Crayon-s">'Y-m-d'Crayon-sy">)
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-10">Crayon-h"> Crayon-o"><Crayon-o">/Crayon-v">div
Crayon-line" id="Crayon-5c891cfe4f563283568781-11">Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-12">Crayon-h"> Crayon-o"><Crayon-e">div Crayon-t">classCrayon-o">=Crayon-s">"p-name"
Crayon-line" id="Crayon-5c891cfe4f563283568781-13">Crayon-h"> Crayon-ta">PHPCrayon-h"> Crayon-k ">echoCrayon-h"> Crayon-e">isnewCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-14">Crayon-h"> Crayon-o"><Crayon-i">aCrayon-h"> Crayon-v">hrefCrayon-o">=Crayon-s">"Crayon-ta">PHPCrayon-h"> Crayon-e">the_permalinkCrayon-sy">(Crayon-sy">)Crayon-sy">;"Crayon-h"> Crayon-v">titleCrayon-o">=Crayon-s">"Crayon-ta">PHPCrayon-h"> Crayon-e">the_titleCrayon-sy">(Crayon-sy">)Crayon-sy">;"
Crayon-line" id="Crayon-5c891cfe4f563283568781-15">Crayon-h"> Crayon-ta">PHPCrayon-h"> Crayon-e">the_titleCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-16">Crayon-h"> Crayon-o"><Crayon-o">/Crayon-e">a
Crayon-line" id="Crayon-5c891cfe4f563283568781-17">Crayon-h"> Crayon-o"><Crayon-o">/Crayon-e">div
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-18">Crayon-h"> Crayon-o"><Crayon-o">/Crayon-e">a
Crayon-line" id="Crayon-5c891cfe4f563283568781-19">Crayon-h"> Crayon-o"><Crayon-o">/Crayon-e">div
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-20">
Crayon-line" id="Crayon-5c891cfe4f563283568781-21">Crayon-h"> Crayon-ta">PHPCrayon-h"> Crayon-st">endwhileCrayon-sy">;Crayon-h"> Crayon-st">elseCrayon-o">:Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-22">Crayon-h"> Crayon-o"><Crayon-e">div Crayon-t">classCrayon-o">=Crayon-s">"no-results"
Crayon-line" id="Crayon-5c891cfe4f563283568781-23">Crayon-h"> Crayon-o"><Crayon-e">pCrayon-o"><Crayon-e">strongCrayon-ta">PHPCrayon-h"> Crayon-e">_eCrayon-sy">(Crayon-s">'出错了'Crayon-sy">)Crayon-sy">;Crayon-h"> Crayon-o"><Crayon-o">/Crayon-v">strongCrayon-o"><Crayon-o">/Crayon-v">p
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-24">Crayon-h"> Crayon-o"><Crayon-v">p
Crayon-line" id="Crayon-5c891cfe4f563283568781-25">Crayon-h"> 很抱歉,没找到您需要的内容,点此返回Crayon-o"><Crayon-i">aCrayon-h"> Crayon-v">hrefCrayon-o">=Crayon-s">"Crayon-ta">PHPCrayon-h"> Crayon-k ">echoCrayon-h"> Crayon-e">site_urlCrayon-sy">(Crayon-sy">)Crayon-sy">;"首页Crayon-o"><Crayon-o">/Crayon-e">a
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-26">Crayon-h"> Crayon-o"><Crayon-o">/Crayon-e">p
Crayon-line" id="Crayon-5c891cfe4f563283568781-27">Crayon-h"> Crayon-o"><Crayon-o">/Crayon-e">divCrayon-o"><Crayon-o">!Crayon-o">--Crayon-e">noResultsCrayon-o">--
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-28">Crayon-h"> Crayon-ta">PHPCrayon-h"> Crayon-st">endifCrayon-sy">;Crayon-h">
Crayon-line" id="Crayon-5c891cfe4f563283568781-29">Crayon-h"> Crayon-o"><Crayon-e">div Crayon-t">classCrayon-o">=Crayon-s">"clr"Crayon-o"><Crayon-o">/Crayon-v">div
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f563283568781-30">Crayon-o"><Crayon-o">/Crayon-v">div

3. 给new特殊标记添加CSS样式,在主体的styles.css文件中加入以下代码

Crayon-5c891cfe4f565067649008" 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">styles.css
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-5c891cfe4f565067649008-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f565067649008-2">2
Crayon-num" data-line="Crayon-5c891cfe4f565067649008-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f565067649008-4">4
Crayon-num" data-line="Crayon-5c891cfe4f565067649008-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f565067649008-6">6
Crayon-num" data-line="Crayon-5c891cfe4f565067649008-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f565067649008-8">8
Crayon-num" data-line="Crayon-5c891cfe4f565067649008-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f565067649008-10">10
Crayon-num" data-line="Crayon-5c891cfe4f565067649008-11">11
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cfe4f565067649008-12">12
Crayon-num" data-line="Crayon-5c891cfe4f565067649008-13">13
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-5c891cfe4f565067649008-1">Crayon-k ">.list-all .one-post .p-name span.newCrayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f565067649008-2">Crayon-h"> Crayon-e ">font-sizeCrayon-sy">:Crayon-i ">12pxCrayon-sy">;
Crayon-line" id="Crayon-5c891cfe4f565067649008-3">Crayon-h"> Crayon-e ">heightCrayon-sy">:Crayon-h"> Crayon-i ">12pxCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f565067649008-4">Crayon-h"> Crayon-e ">line-heightCrayon-sy">:Crayon-h"> Crayon-i ">12pxCrayon-sy">;
Crayon-line" id="Crayon-5c891cfe4f565067649008-5">Crayon-h"> Crayon-e ">paddingCrayon-sy">:Crayon-h"> Crayon-i ">2pxCrayon-h"> Crayon-i ">10pxCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f565067649008-6">Crayon-h"> Crayon-e ">backgroundCrayon-sy">:Crayon-h"> Crayon-i ">#dd3333Crayon-sy">;
Crayon-line" id="Crayon-5c891cfe4f565067649008-7">Crayon-h"> Crayon-e ">colorCrayon-sy">:Crayon-h"> Crayon-i ">#fffCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f565067649008-8">Crayon-h"> Crayon-e ">border-radiusCrayon-sy">:Crayon-h"> Crayon-i ">3pxCrayon-sy">;
Crayon-line" id="Crayon-5c891cfe4f565067649008-9">Crayon-h"> Crayon-e ">-moz-border-radiusCrayon-sy">:Crayon-h"> Crayon-i ">3pxCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f565067649008-10">Crayon-h"> Crayon-e ">-webkit-border-radiusCrayon-sy">:Crayon-h"> Crayon-i ">3pxCrayon-sy">;
Crayon-line" id="Crayon-5c891cfe4f565067649008-11">Crayon-h"> Crayon-e ">floatCrayon-sy">:Crayon-h"> Crayon-i ">leftCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891cfe4f565067649008-12">Crayon-h"> Crayon-e ">marginCrayon-sy">:Crayon-h"> Crayon-i ">0pxCrayon-h"> Crayon-i ">0pxCrayon-h"> Crayon-i ">0pxCrayon-h"> Crayon-i ">10pxCrayon-sy">;
Crayon-line" id="Crayon-5c891cfe4f565067649008-13">Crayon-sy">}

4. 最终效果如下:

category-new-post

相关文章

WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的...
这两段代码可以让你先体验一下WordPress 3.0的菜单样式 首先在functions.php添加如下代码: register_n...
有人说 WordPress 本身的 SEO 就比较好,我想这个和 WordPress 可以方便的自定义文章的固定链接有分不开...
曾经给大家介绍了在 WordPress 后台移除主题编辑器,今天继续加深,直接关闭 WordPress 后台的文件编辑...
WordPress之iNove主题内容页增加公告栏的方法,导航栏下面默认的公告栏只能在首页显示,只要修改一个文...
大多数WordPress用户都知道该怎么从数千个WordPress主题里挑出自己喜欢,但要自己开发新主题恐怕不是人...