WordPress: Template Tags/get year link:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
无编辑摘要
 
第1行: 第1行:
== Description ==
== 描述 ==
== 描述 ==


Returns the yearly archive [[WordPress:Glossary#URI and URL|URL]] to a specific year for use in [[WordPress:Glossary#PHP|PHP]]. It does NOT display the URL. If year is set to <tt>&#39;&#39;</tt>, the tag returns the URL for the current year's archive.
返回某年的归档[[WordPress:Glossary#URI and URL|URL]],用于[[WordPress:Glossary#PHP|PHP]]中。不显示URL。如果年份设置为<tt>&#39;&#39;</tt>,标签向当前年份归档返回了URL。
返回某年的归档[[WordPress:Glossary#URI and URL|URL]],用于[[WordPress:Glossary#PHP|PHP]]中。不显示URL。如果年份设置为<tt>&#39;&#39;</tt>,标签向当前年份归档返回了URL。
== Usage ==


== 用法 ==
== 用法 ==


%%% <?php get_year_link('year'); ?> %%%
%%% <?php get_year_link('year'); ?> %%%
%%% <?php get_year_link('year'); ?> %%%
== Examples ==


== 例子==
== 例子==
=== Year as Link ===


=== 年份作为链接 ===
=== 年份作为链接 ===
Returns the URL for the current year's archive, displaying it as a link in the anchor tag by using the PHP echo command.


返回当年存档的URL,使用PHP echo命令行,在anchor标签中显示URL为一个链接。
返回当年存档的URL,使用PHP echo命令行,在anchor标签中显示URL为一个链接。
&lt;a href="<?php echo get_year_link(<nowiki>''</nowiki>); ?>"&gt;Posts from this year&lt;/a&gt;


&lt;a href="<?php echo get_year_link(<nowiki>''</nowiki>); ?>"&gt;Posts from this year&lt;/a&gt;
&lt;a href="<?php echo get_year_link(<nowiki>''</nowiki>); ?>"&gt;Posts from this year&lt;/a&gt;
=== Year as a variable ===


=== 年份作为变数 ===
=== 年份作为变数 ===
Returns URL for the archive year 2003, assigning it to the variable $year03. The variable can then be used elsewhere in a page.


返回2003年存档的URL,并且指派这个URL为变数$03年。变数可以在网页的其它位置上使用。
返回2003年存档的URL,并且指派这个URL为变数$03年。变数可以在网页的其它位置上使用。
<?php $year03 = get_year_link(2003); ?>


<?php $year03 = get_year_link(2003); ?>
<?php $year03 = get_year_link(2003); ?>
=== Using With PHP Variables ===


=== 与PHP 变数一起使用 ===
=== 与PHP 变数一起使用 ===


PHP code block for use within [[WordPress:The Loop]]: Assigns year to the variable $arc_year. This is used with the get_year_link() tag, which returns the URL as a link to the yearly archive for a post, displaying it within an anchor tag with the PHP echo command. See [[WordPress:Formatting Date and Time]] for info on format strings used in [[WordPress:Template Tags/get_the time|get_the_time()]] tag.
[[WordPress:The Loop|The Loop]]内可以使用的PHP代码块:将年份指定为变数$arc_year。变数在get_year_link()标签内部使用,这个标签返回URL作为一个链接,连接到文章的年份存档中,在一个anchor 标签中,将它和PHP echo命令一起显示。请看看[[WordPress:Formatting Date and Time|日期和时间格式]],有关用在[[WordPress:Template Tags/get_the time|get_the_time()]]标签中的格式字符串的信息。
 
[[WordPress:The Loop|The Loop]]内可以使用的PHP代码块:将年份指定为变数$arc_年份。变数在get_year_link()标签内部使用,这个标签返回URL作为一个链接,连接到文章的年份存档中,在一个anchor 标签中,将它和PHP echo命令一起显示。请看看[[WordPress:Formatting Date and Time|日期和时间格式]],有关用在[[WordPress:Template Tags/get_the time|get_the_time()]]标签中的格式字符串的信息。
 
<?php
$arc_year = get_the_time('Y');
?>
&lt;a href="<?php echo get_year_link(<nowiki>$arc_year</nowiki>); ?>"&gt;<?php the_time('Y') ?> archive&lt;/a&gt;


<?php
<?php
第58行: 第29行:
  ?>
  ?>
  &lt;a href="<?php echo get_year_link(<nowiki>$arc_year</nowiki>); ?>"&gt;<?php the_time('Y') ?> archive&lt;/a&gt;
  &lt;a href="<?php echo get_year_link(<nowiki>$arc_year</nowiki>); ?>"&gt;<?php the_time('Y') ?> archive&lt;/a&gt;
== Parameters ==


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


; year : (''integer'') The year for the archive. Use <tt>&#39;&#39;</tt> to assign current year.
; year : (''integer'') 归档的年份。使用<tt>&#39;&#39;</tt>指派当前的年份。
 
; 年份 : (''整数'')归档的年份。使用<tt>&#39;&#39;</tt>指派当前的年份。
 
== Related ==
 
{{Tag Link Tags}}


{{PHP Function Tag Footer}}


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

2008年7月16日 (三) 11:21的最新版本

描述[ ]

返回某年的归档URL,用于PHP中。不显示URL。如果年份设置为'',标签向当前年份归档返回了URL。

用法[ ]

%%% <?php get_year_link('year'); ?> %%%

例子[ ]

年份作为链接[ ]

返回当年存档的URL,使用PHP echo命令行,在anchor标签中显示URL为一个链接。

<a href="<?php echo get_year_link(''); ?>">Posts from this year</a>

年份作为变数[ ]

返回2003年存档的URL,并且指派这个URL为变数$03年。变数可以在网页的其它位置上使用。

<?php $year03 = get_year_link(2003); ?>

与PHP 变数一起使用[ ]

The Loop内可以使用的PHP代码块:将年份指定为变数$arc_year。变数在get_year_link()标签内部使用,这个标签返回URL作为一个链接,连接到文章的年份存档中,在一个anchor 标签中,将它和PHP echo命令一起显示。请看看日期和时间格式,有关用在get_the_time()标签中的格式字符串的信息。

<?php

$arc_year = get_the_time('Y');
?>
<a href="<?php echo get_year_link($arc_year); ?>"><?php the_time('Y') ?> archive</a>

参数[ ]

year
(integer) 归档的年份。使用''指派当前的年份。


相关的[ ]

模板:标签 链接标签

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