post_type_archive_title() - WordPress 函数参考中文文档

返回介绍

post_type_archive_title()

发布于 2017-09-11 字数2928 浏览 1029 评论 0

post_type_archive_title( string $prefix = '',  bool $display = true )

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.


参数

$prefix

(string)
(Optional)
What to display before the title.

Default value: ”

$display

(bool)
(Optional)
Whether to display or retrieve title.

Default value: true


返回值

(string|void) Title when retrieving, null when displaying or failure.


源代码

File: wp-includes/general-template.php

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 );

	/**
	 * Filters 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;
}

更新日志

Version 描述
3.1.0 Introduced.

相关函数

Uses

  • wp-includes/general-template.php:
    post_type_archive_title
  • wp-includes/query.php:
    is_post_type_archive()
  • wp-includes/query.php:
    get_query_var()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/post.php:
    get_post_type_object()

Used By

  • wp-includes/general-template.php:
    wp_get_document_title()
  • wp-includes/general-template.php:
    get_the_archive_title()
  • wp-includes/general-template.php:
    feed_links_extra()
  • wp-includes/general-template.php:
    wp_title()

User Contributed Notes

  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

    Display the Custom Post Type title:

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!