函数文档

get_post_format_link()

💡 云策文档标注

概述

get_post_format_link() 函数用于返回文章格式索引的链接。它接受文章格式的 slug 作为参数,并返回对应的文章格式术语链接或错误值。

关键要点

  • 参数:$format(字符串,必需),指定文章格式的 slug。
  • 返回值:字符串(链接)、WP_Error 或 false(如果未找到或出错)。
  • 内部实现:通过 get_term_by() 获取术语,然后使用 get_term_link() 生成链接。
  • 相关函数:get_term_link()、get_term_by()、is_wp_error()。
  • 引入版本:WordPress 3.1.0。

代码示例

function get_post_format_link( $format ) {
    $term = get_term_by( 'slug', 'post-format-' . $format, 'post_format' );
    if ( ! $term || is_wp_error( $term ) ) {
        return false;
    }
    return get_term_link( $term );
}

📄 原文内容

Returns a link to a post format index.

Parameters

$formatstringrequired
The post format slug.

Return

string|WP_Error|false The post format term link.

Source

function get_post_format_link( $format ) {
	$term = get_term_by( 'slug', 'post-format-' . $format, 'post_format' );
	if ( ! $term || is_wp_error( $term ) ) {
		return false;
	}
	return get_term_link( $term );
}

Changelog

Version Description
3.1.0 Introduced.