get_post_type_archive_link()获取某个文章类型的文章列表页链接

目录

描述

Retrieve the permalink for a post type archive.

get_post_type_archive_link() 描述

用法

<?php get_post_type_archive_link$post_type ); ?>

get_post_type_archive_link() 用法

参数

$post_type

(string) (必填) Post type

默认值: None

get_post_type_archive_link() 参数

返回值

(mixed

Archive URL for the requested post type. Will return false if $post_type does not exist or $post_type has no archive.

get_post_type_archive_link() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
   <a href="<?php echo get_post_type_archive_link( 'movies' ); ?>">Movies Archive</a>

get_post_type_archive_link() 示例

历史

添加于 版本: 3.1.0

get_post_type_archive_link() 历史

源文件

get_post_type_archive_link() 函数的代码位于 wp-includes/link-template.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve the permalink for a post type archive.
 *
 * @since 3.1.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param string $post_type Post type
 * @return string|false The post type archive permalink.
 */
function get_post_type_archive_link( $post_type ) {
	global $wp_rewrite;
	if ( ! $post_type_obj = get_post_type_object( $post_type ) )
		return false;

	if ( ! $post_type_obj->has_archive )
		return false;

	if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) {
		$struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive;
		if ( $post_type_obj->rewrite['with_front'] )
			$struct = $wp_rewrite->front . $struct;
		else
			$struct = $wp_rewrite->root . $struct;
		$link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );
	} else {
		$link = home_url( '?post_type=' . $post_type );
	}

	/**
	 * Filter the post type archive permalink.
	 *
	 * @since 3.1.0
	 *
	 * @param string $link      The post type archive permalink.
	 * @param string $post_type Post type name.
	 */
	return apply_filters( 'post_type_archive_link', $link, $post_type );
}

get_post_type_archive_link() 源文件