post_type_archive_title()显示自定义文章类型名称

目录

描述

Display or retrieve title for a post type archive.

This is optimized for archive.php and archive-{posttype}.php template files for displaying the title of the post type.

post_type_archive_title() 描述

用法

<?php post_type_archive_title$prefix$display ); ?>

post_type_archive_title() 用法

参数

$prefix

(string) (可选) What to display before the title

默认值: None

Note: The $prefix argument is currently ignored if the $display argument is false.
See http://core.trac.wordpress.org/ticket/16632

$display

(bool) (可选) Whether to display or retrieve title

默认值: true

post_type_archive_title() 参数

返回值

(string) 

Title when retrieving, null when displaying or failure.

post_type_archive_title() 返回值

示例

Display the Custom Post Type title:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<h1><?php post_type_archive_title(); ?></h1>

post_type_archive_title() 示例

历史

  • 添加于 版本: 3.1.0

post_type_archive_title() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Display or retrieve title for a post type archive.
 *
 * This is optimized for archive.php and archive-{$post_type}.php template files
 * for displaying the title of the post type.
 *
 * @since 3.1.0
 *
 * @param string $prefix  Optional. What to display before the title.
 * @param bool   $display Optional, default is true. Whether to display or retrieve title.
 * @return string|void Title when retrieving, null when displaying or failure.
 */
function post_type_archive_title( $prefix = '', $display = true ) {
	if ( ! is_post_type_archive() )
		return;

	$post_type = get_query_var( 'post_type' );
	if ( is_array( $post_type ) )
		$post_type = reset( $post_type );

	$post_type_obj = get_post_type_object( $post_type );

	/**
	 * Filter the post type archive title.
	 *
	 * @since 3.1.0
	 *
	 * @param string $post_type_name Post type 'name' label.
	 * @param string $post_type      Post type.
	 */
	$title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );

	if ( $display )
		echo $prefix . $title;
	else
		return $prefix . $title;
}

post_type_archive_title() 源文件

相关