WordPress: Template Tags/the date:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
无编辑摘要
 
第1行: 第1行:
== Description ==
== 描述 ==
== 描述 ==
Displays or returns the date of a post, or a set of posts if published on the same day.


如果文章都是以同样的方式发表的,显示或者返回一篇文章或者一组文章的发表日期。
如果文章都是以同样的方式发表的,显示或者返回一篇文章或者一组文章的发表日期。


<div style="text-decoration:none; padding: 10px; margin: 10px 0px 5px; background-color: #f0f0f0; border: 1px solid darkslateblue">'''SPECIAL NOTE:''' When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the [[WordPress:Template Tags|Template Tag]] [[WordPress:Template Tags/the time|the_time()]] with a [[WordPress:Formatting_Date_and_Time|date-specific format string]].</div>
<div style="text-decoration:none; padding: 10px; margin: 10px 0px 5px; background-color: #f0f0f0; border: 1px solid darkslateblue">'''特别要注意:''' 当一个网页上有几篇文章,这些文章是在同一天发表的, the_date() 只会显示第一篇文章的发表日期, (就是, the_date()的第一个例子)。要重复在同一天发表的文章的日期,你应该使用 [[WordPress:Template Tags|模板标签]] [[WordPress:Template Tags/the time|the_time()]] 拥有一个[[WordPress:Formatting_Date_and_Time|特别日期格式字符串]]</div>
 


<div style="text-decoration:none; padding: 10px; margin: 10px 0px 5px; background-color: #f0f0f0; border: 1px solid darkslateblue">'''特别要注意:''' 当一个网页上有几篇文章,这些文章是在同一天发表的, the_日期() 只会显示第一篇文章的发表日期, (就是, the_日期()的第一个例子)。要重复在同一天发表的文章的日期,你应该使用 [[WordPress:Template Tags|模板标签]] [[WordPress:Template Tags/the time|the_时间()]] 拥有一个[[WordPress:Formatting_Date_and_Time|特别日期格式字符串]]。</div>
This tag must be used within [[WordPress:The Loop]].
必须在[[WordPress:The Loop|The Loop]]内部使用这个标签。
必须在[[WordPress:The Loop|The Loop]]内部使用这个标签。
== Usage ==
== 用法 ==


%%% <?php the_date('format', 'before', 'after', echo); ?> %%%
%%% <?php the_date('format', 'before', 'after', echo); ?> %%%
== 用法 ==
%%% <?php the_日期('格式', '之前', '之后', echo); ?> %%%
== Examples ==
=== Default Usage ===
Displays the date using defaults.
&lt;p&gt;Date posted: <?php the_date(); ?>&lt;/p&gt;


== 例子 ==
== 例子 ==
第37行: 第16行:
使用默认格式,显示日期。
使用默认格式,显示日期。


  &lt;p&gt;文章发表的日期: <?php the_日期(); ?>&lt;/p&gt;
  &lt;p&gt;文章发表的日期: <?php the_date(); ?>&lt;/p&gt;
 
=== Date as Year, Month, Date in Heading ===


=== 标签中的年,月,日,日期===
=== 标签中的年,月,日,日期===
Displays the date using the <code>'2007-07-23'</code> format (ex: 2004-11-30), inside an &lt;h2&gt; tag.


使用<code>'2007-07-23'</code>格式 (例如: 2004-11-30)显示日期,在&lt;h2&gt;标签内部。
使用<code>'2007-07-23'</code>格式 (例如: 2004-11-30)显示日期,在&lt;h2&gt;标签内部。
第49行: 第24行:
  <?php the_date('Y-m-d', '&lt;h2&gt;', '&lt;/h2&gt;'); ?>
  <?php the_date('Y-m-d', '&lt;h2&gt;', '&lt;/h2&gt;'); ?>


<?php the_日期('Y-m-d', '&lt;h2&gt;', '&lt;/h2&gt;'); ?>
===标题中的日期,使用$my_date 变量===
 
=== Date in Heading Using $my_date Variable===
 
===标题中的日期,使用$my_date 变数===


Returns the date in the default format inside an &lt;h2&gt; tag and assigns it to the $my_date variable. The variable's value is then displayed with the PHP echo command.
在&lt;h2&gt;标签中,将日期返回为默认格式,并且将日期分发给 $my_date 变量。变量的值,就会与PHP echo命令行一起显示。
 
在&lt;h2&gt;标签中,将日期返回为默认格式,并且将日期分发给$我的_日期变数。变数的值,就会与PHP echo命令行一起显示。


  <?php $my_date = the_date(&#39;&#39;, &#39;&#39;, &#39;&#39;, FALSE); echo $my_date; ?>
  <?php $my_date = the_date(&#39;&#39;, &#39;&#39;, &#39;&#39;, FALSE); echo $my_date; ?>
<?php $我的_日期 = the_日期(&#39;&#39;, &#39;&#39;, &#39;&#39;, 错误的); echo $我的_日期; ?>
== Parameters ==


== 参数 ==
== 参数 ==


; format : (''string'') The format for the date. Defaults to the date format configured in your WordPress options. See [[WordPress:Formatting Date and Time]].
; format : (''string'') 日期的格式。默认为WordPress选项中设置的日期格式。请看看[[WordPress:Formatting Date and Time|日期和时间格式]]
; before : (''string'') Text to place before the date. There is no default.
; before : (''string'') 置于日期前的文本。没有默认设置。
; after : (''string'') Text to place after the date. There is no default.
; after : (''string'') 置于日期后的文本。没有默认设置。
; echo : (''boolean'') Display the date (<tt>TRUE</tt>), or return the date to be used in PHP (<tt>FALSE</tt>). Defaults to <tt>TRUE</tt>.
; echo : (''boolean'') 显示日期(<tt>true</tt>),或者返回日期用于PHP(<tt>false</tt>)。默认为<tt>true</tt>。
 
;格式:(''string'')日期的格式。默认为WordPress选项中设置的日期格式。请看看[[WordPress:Formatting Date and Time|日期和时间格式]]。
;之前:(''string'')置于日期前的文本。没有默认设置。
;之后:(''string'')置于日期后的文本。没有默认设置。
; echo : (''boolean'')显示日期(<tt>正确的</tt>),或者返回日期用于PHP(<tt>错误的</tt>)。默认为<tt>正确的</tt>。
 
== Related ==
 
{{Tag Date Tags}}
 
{{PHP Function Tag Footer}}


== 相关的 ==
== 相关的 ==

2008年7月11日 (五) 17:41的最新版本

描述[ ]

如果文章都是以同样的方式发表的,显示或者返回一篇文章或者一组文章的发表日期。

特别要注意: 当一个网页上有几篇文章,这些文章是在同一天发表的, the_date() 只会显示第一篇文章的发表日期, (就是, the_date()的第一个例子)。要重复在同一天发表的文章的日期,你应该使用 模板标签 the_time() 拥有一个特别日期格式字符串

必须在The Loop内部使用这个标签。

用法[ ]

%%% <?php the_date('format', 'before', 'after', echo); ?> %%%

例子[ ]

默认用法[ ]

使用默认格式,显示日期。

<p>文章发表的日期: <?php the_date(); ?></p>

标签中的年,月,日,日期[ ]

使用'2007-07-23'格式 (例如: 2004-11-30)显示日期,在<h2>标签内部。

<?php the_date('Y-m-d', '<h2>', '</h2>'); ?>

标题中的日期,使用$my_date 变量[ ]

在<h2>标签中,将日期返回为默认格式,并且将日期分发给 $my_date 变量。变量的值,就会与PHP echo命令行一起显示。

<?php $my_date = the_date('', '', '', FALSE); echo $my_date; ?>

参数[ ]

format
(string) 日期的格式。默认为WordPress选项中设置的日期格式。请看看日期和时间格式
before
(string) 置于日期前的文本。没有默认设置。
after
(string) 置于日期后的文本。没有默认设置。
echo
(boolean) 显示日期(true),或者返回日期用于PHP(false)。默认为true

相关的[ ]

模板:标签 日期 标签

模板:PHP 函数 标签 页底文字