^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_month_link()用法示例

get_month_link( bool|int $year,  bool|int $month )

Retrieves the permalink for the month archives with year.


描述


参数

$year

(bool|int)
(Required)
False for current year. Integer of year.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

$month

(bool|int)
(Required)
False for current month. Integer of month.


返回值

(string) The permalink for the specified month and year archive.


源代码

File: wp-includes/link-template.php

function get_month_link($year, $month) {
	global $wp_rewrite;
	if ( !$year )
		$year = gmdate('Y', current_time('timestamp'));
	if ( !$month )
		$month = gmdate('m', current_time('timestamp'));
	$monthlink = $wp_rewrite->get_month_permastruct();
	if ( !empty($monthlink) ) {
		$monthlink = str_replace('%year%', $year, $monthlink);
		$monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
		$monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) );
	} else {
		$monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) );
	}

	/**
	 * Filters the month archive permalink.
	 *
	 * @since 1.5.0
	 *
	 * @param string $monthlink Permalink for the month archive.
	 * @param int    $year      Year for the archive.
	 * @param int    $month     The month for the archive.
	 */
	return apply_filters( 'month_link', $monthlink, $year, $month );
}

更新日志

Version 描述
1.0.0 Introduced.

相关函数

Uses

  • wp-includes/formatting.php:
    zeroise()
  • wp-includes/functions.php:
    current_time()
  • wp-includes/link-template.php:
    home_url()
  • wp-includes/link-template.php:
    month_link
  • wp-includes/link-template.php:
    user_trailingslashit()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/class-wp-rewrite.php:
    WP_Rewrite::get_month_permastruct()
  • Show 2 more uses


Used By

  • wp-includes/general-template.php:
    wp_get_archives()
  • wp-includes/general-template.php:
    get_calendar()
  • wp-includes/canonical.php:
    redirect_canonical()

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Month Archive as Link

    Returns the URL to the current month’s archive as a link by displaying it within an anchor tag with the PHP echo command.

    
    <a href="<?php echo get_month_link('', ''); ?>">All posts this month</a>
    
  2. Assigning Specific Month to Variable

    Returns URL to the archive for October 2004, assigning it to the variable $oct_04. The variable can then be used elsewhere in a page.

    
    <?php $oct_04 = get_month_link('2004', '10'); ?>
    

    Use With PHP Variables

    PHP code block for use within The Loop: Assigns year and month of a post to the variables $arc_year and $arc_month. These are used with the get_month_link() tag, which returns the URL as a link to the monthly archive for that post, displaying it within an anchor tag with the PHP echo command. See Formatting Date and Time for info on format strings used in get_the_time() tag.

    
    <?php $archive_year  = get_the_time('Y'); ?>
    <?php $archive_month = get_the_time('m'); ?>
    
    <a href="<?php echo get_month_link( $archive_year, $archive_month ); ?>">
    Archive for <?php the_time('F Y'); ?>
    </a>
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈