WordPress: Template Tags/get year link:修订间差异
(新页面: == Description == Returns the yearly archive URL to a specific year for use in PHP. It does NOT display the URL. If year is ...) |
无编辑摘要 |
||
第1行: | 第1行: | ||
== Description == | == 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>''</tt>, the tag returns the URL for the current year's archive. | 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>''</tt>, the tag returns the URL for the current year's archive. | ||
返回某年的归档[[WordPress:Glossary#URI and URL|URL]],用于[[WordPress:Glossary#PHP|PHP]]中。不显示URL。如果年份设置为<tt>''</tt>,标签向当前年份归档返回了URL。 | |||
== Usage == | |||
== 用法 == | |||
%%% <?php get_year_link('year'); ?> %%% | |||
%%% <?php get_year_link('year'); ?> %%% | %%% <?php get_year_link('year'); ?> %%% | ||
== Examples == | == Examples == | ||
== 例子== | |||
=== Year as Link === | === 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. | 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为一个链接。 | |||
<a href="<?php echo get_year_link(<nowiki>''</nowiki>); ?>">Posts from this year</a> | <a href="<?php echo get_year_link(<nowiki>''</nowiki>); ?>">Posts from this year</a> | ||
<a href="<?php echo get_year_link(<nowiki>''</nowiki>); ?>">Posts from this year</a> | |||
=== Year as a variable === | === 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. | 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年。变数可以在网页的其它位置上使用。 | |||
<?php $year03 = get_year_link(2003); ?> | <?php $year03 = get_year_link(2003); ?> | ||
<?php $year03 = get_year_link(2003); ?> | |||
=== Using With PHP Variables === | === Using With PHP Variables === | ||
=== 与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. | 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_年份。变数在get_year_link()标签内部使用,这个标签返回URL作为一个链接,连接到文章的年份存档中,在一个anchor 标签中,将它和PHP echo命令一起显示。请看看[[WordPress:Formatting Date and Time|日期和时间格式]],有关用在[[WordPress:Template Tags/get_the time|get_the_time()]]标签中的格式字符串的信息。 | |||
<?php | <?php | ||
$arc_year = get_the_time('Y'); | |||
?> | |||
<a href="<?php echo get_year_link(<nowiki>$arc_year</nowiki>); ?>"><?php the_time('Y') ?> archive</a> | |||
<?php | |||
$arc_year = get_the_time('Y'); | $arc_year = get_the_time('Y'); | ||
?> | ?> | ||
第31行: | 第60行: | ||
== Parameters == | == Parameters == | ||
== 参数== | |||
; year : (''integer'') The year for the archive. Use <tt>''</tt> to assign current year. | ; year : (''integer'') The year for the archive. Use <tt>''</tt> to assign current year. | ||
; 年份 : (''整数'')归档的年份。使用<tt>''</tt>指派当前的年份。 | |||
== Related == | == Related == | ||
第39行: | 第72行: | ||
{{PHP Function Tag Footer}} | {{PHP Function Tag Footer}} | ||
== 相关的 == | |||
{{标签 链接标签}} | |||
{{PHP函数标签 页底文字}} |
2008年7月5日 (六) 17:29的版本
Description
描述
Returns the yearly archive URL to a specific year for use in PHP. It does NOT display the URL. If year is set to '', the tag returns the URL for the current year's archive. 返回某年的归档URL,用于PHP中。不显示URL。如果年份设置为'',标签向当前年份归档返回了URL。
Usage
用法
%%% <?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为一个链接。
<a href="<?php echo get_year_link(''); ?>">Posts from this year</a>
<a href="<?php echo get_year_link(''); ?>">Posts from this year</a>
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年。变数可以在网页的其它位置上使用。
<?php $year03 = get_year_link(2003); ?>
<?php $year03 = get_year_link(2003); ?>
Using With PHP Variables
与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 get_the_time() tag.
The Loop内可以使用的PHP代码块:将年份指定为变数$arc_年份。变数在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>
<?php
$arc_year = get_the_time('Y'); ?> <a href="<?php echo get_year_link($arc_year); ?>"><?php the_time('Y') ?> archive</a>
Parameters
参数
- year
- (integer) The year for the archive. Use '' to assign current year.
- 年份
- (整数)归档的年份。使用''指派当前的年份。