Home Backend Development PHP Tutorial WordPress自定义时间显示格式_php实例

WordPress自定义时间显示格式_php实例

May 16, 2016 pm 08:19 PM
wordpress

在帮King改他的私人情侣博客模版~找了一些找了,总算是把时间显示为想要的格式了。于是将获得的一些信息记下,供备忘,亦供朋友们参考。

WordPress 通过一系列的时间日期函数控制时间日期的输出,下面介绍几个常用的函数:

1、the_date_xml() 函数

调用格式:

复制代码 代码如下:


输出格式:YYYY-MM-DD

如:2005-05-14

2、the_date()函数

说明:此 函数一般用于显示时间日期。根据官方文档的说法,当一个页面上有多篇发布于同一天的档案时,the_date() 函数仅在最先引用处显示,在这种情况下最好使用 the_time() 函数。见:http://codex.wordpress.org/Template_Tags/the_date

调用格式:

复制代码 代码如下:


参数表:

format:(字符串型)定义时间日期格式的参数。
before:(字符串型)日期前放置的文本,无缺省值。
after:(字符串型)日期后放置的文本,无缺省值。
echo:(布尔型)显示日期 (TRUE),或返回供 PHP 使用的日期(FALSE)。缺省值为 TRUE。

3、the_time() 函数

说明:此函数用于显示时间日期。根据官方文档的说法,此函数必须被使用在循环内。见:http://codex.wordpress.org/Template_Tags/the_time

调用格式:

复制代码 代码如下:


参数表:

format:(字符串型)定义时间日期格式的参数。

4、get_the_time() 函数

说明:根据官方文档的说法,此函数仅向 PHP 返回时间信息,并不显示时间日期,且必须被使用在循环内。见:http://codex.wordpress.org/Template_Tags/get_the_time

调用格式: php

参数表:

format:(字符串型)定义时间日期格式的参数。
以上三个函数format 参数可以使用的各项值:

a = 一般在12小时制显示时使用,显示当前是 am(上午)或 pm(下午) A = 功能同上,区别是 am 或 pm 为大写

d = 一月中的哪一天,固定以两位数显示

F = 文字全称表示的月份

g = 12小时制的小时数,位数根据实际的时间决定 G = 24小时制的小时数,位数根据实际的时间决定

h = 12小时制的小时数,固定以两位数显示 H = 24小时制的小时数,固定以两位数显示

注:如当前时间是早上8点,用 h 参数输出的结果为 08,用 g 参数输出的结果为 8,换成大写后仅改变时制。

i = 当前分钟数 I = 输出一个零,不知何用,望知道的兄弟指教。(大写 i)

j = 一月中的哪一天,位数根据实际的日期决定

l = 文字表示的星期(小写 L) L = 输出一个零,不知何用,望知道的兄弟指教。

m = 数字表示的月份 M = 英文缩写的月份

s = 当前秒数 S = 一般跟随参数 j 使用,效果是在天数后加上序数词后坠(st, nd ,rd 等)

Y = 4位数的年份 y = 2位数的年份

注:参数区分大小写,写在参数引号内的非参数字符不做处理,直接输出。

例如,以下格式字串:

l, F j, Y

将生成如下格式的日期:

星期五, 九月 24, 2004

5、single_month_title() 函数

调用格式:

复制代码 代码如下:


参数表:

prefix:年和月的前缀
输出格式:prefix + MONTH + prefix + YEAR

如prefix 参数为"*“,显示结果将会是如下的样子:

*February * 2004

最终帮King改的时间函数为the_time(‘Y年m月d日,H时s分i秒') 显示效果就是:发表于: 2010年06月12日,23时14分32秒

大家可以举一反三。找到自己想要的效果

以上所述就是本文的全部内容了,希望对大家学习WordPress能够有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP vs. Flutter: The best choice for mobile development PHP vs. Flutter: The best choice for mobile development May 06, 2024 pm 10:45 PM

PHP and Flutter are popular technologies for mobile development. Flutter excels in cross-platform capabilities, performance and user interface, and is suitable for applications that require high performance, cross-platform and customized UI. PHP is suitable for server-side applications with lower performance and not cross-platform.

How to change page width in wordpress How to change page width in wordpress Apr 16, 2024 am 01:03 AM

You can easily modify your WordPress page width by editing your style.css file: Edit your style.css file and add .site-content { max-width: [your preferred width]; }. Edit [your preferred width] to set the page width. Save changes and clear cache (optional).

How to create a product page in wordpress How to create a product page in wordpress Apr 16, 2024 am 12:39 AM

Create a product page in WordPress: 1. Create the product (name, description, pictures); 2. Customize the page template (add title, description, pictures, buttons); 3. Enter product information (stock, size, weight); 4 . Create variations (different colors, sizes); 5. Set visibility (public or hidden); 6. Enable/disable comments; 7. Preview and publish the page.

In which folder are wordpress articles located? In which folder are wordpress articles located? Apr 16, 2024 am 10:29 AM

WordPress posts are stored in the /wp-content/uploads folder. This folder uses subfolders to categorize different types of uploads, including articles organized by year, month, and article ID. Article files are stored in plain text format (.txt), and the filename usually includes its ID and title.

Where is the wordpress template file? Where is the wordpress template file? Apr 16, 2024 am 11:00 AM

WordPress template files are located in the /wp-content/themes/[theme name]/ directory. They are used to determine the appearance and functionality of the website, including header (header.php), footer (footer.php), main template (index.php), single article (single.php), page (page.php), Archive (archive.php), category (category.php), tag (tag.php), search (search.php) and 404 error page (404.php). By editing and modifying these files, you can customize the appearance of your WordPress website

How to search for authors in WordPress How to search for authors in WordPress Apr 16, 2024 am 01:18 AM

Search for authors in WordPress: 1. Once logged in to your admin panel, navigate to Posts or Pages, enter the author name using the search bar, and select Author in Filters. 2. Other tips: Use wildcards to broaden your search, use operators to combine criteria, or enter author IDs to search for articles.

Which version of wordpress is stable? Which version of wordpress is stable? Apr 16, 2024 am 10:54 AM

The most stable WordPress version is the latest version because it contains the latest security patches, performance enhancements, and introduces new features and improvements. In order to update to the latest version, log into your WordPress dashboard, go to the Updates page and click Update Now.

What language is used to develop WordPress? What language is used to develop WordPress? Apr 16, 2024 am 12:03 AM

WordPress is developed using PHP language as its core programming language for handling database interactions, form processing, dynamic content generation, and user requests. PHP was chosen for reasons including cross-platform compatibility, ease of learning, active community, and rich library and frameworks. Apart from PHP, WordPress also uses languages ​​like HTML, CSS, JavaScript, SQL, etc. to enhance its functionality.

See all articles