WordPress:Template Tags/get month link
来自站长百科
描述[ ]
返回某年某月的归档URL,用于PHP中。不显示URL。如果年份和月份参数设置为'',标签向当前月份归档返回了URL。
用法[ ]
%%% <?php get_month_link('year', 'month'); ?> %%%
例子[ ]
每月归档作为链接[ ]
返回当月存档的URL,作为链接,将这个URL放到一个anchor标签中和PHP echo命令一起显示。
<a href="<?php echo get_month_link('', ''); ?>">All posts this month</a>
将某月指定为变数[ ]
返回2004年10月存档的URL,将这个URL指定为变数$oct_04,变数就可以用在网页的其它位置。
<?php $oct_04 = get_month_link('2004', '10'); ?>
与PHP 变数一起使用[ ]
The Loop内使用的PHP代码块:将一篇文章的年份和月份指定为变数$arc_year和 $arc_month。这些变数与get_month_link()标签一起使用,get_month_link()标签返回URL作为一个链接,连接到文章的每月存档中,在一个anchor 标签中,将它和PHP echo命令一起显示。请看看日期和时间格式,有关用在get_the_time()标签中的格式字符串的信息。
<?php
$arc_year = get_the_time('Y'); $arc_month = get_the_time('m'); ?> <a href="<?php echo get_month_link("$arc_year", "$arc_month"); ?>">archive for <?php the_time('F Y') ?></a>
参数[ ]
- year
- (integer) 归档的年份。使用''指定当前的年份。
- month
- (integer) 归档的月份。使用''指定当前的月份。