Function Reference/get the title

来自WordPress中文文档
跳转至: 导航搜索

Description

This function will return the title of a post for a given post ID. If the post is protected or private, the word "Protected: " or "Private: " will be prepended to the title. It can be used inside or outside of The Loop. If used outside the loop an ID must be specified.

Usage

%%% <?php echo get_the_title($ID); ?> %%%

Parameters

tt$ID/tt
(integer) (optional) Post ID or leave empty to use current post in The Loop
Default: Nonenoinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki检查到模板循环:模板:Parameter/nowiki/pre 检查到模板循环:模板:Parameter

The usage of this template is below: prenowiki检查到模板循环:模板:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

Return Values

tt/tt
tt style=color:gray@return/tt (string) tt style=color:blue/tt: Post title. If the post is protected or private, the word "Protected: " or "Private: " prepended to the title.noinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Description

This template is for standardizing how return values look in the Function Reference and in Template Tags.

Parameters

(1|param|param)
Return param or value (also can be: null, void...).
(2|datatype|datatype)
Datatype of return value.
(3|description|description)
Description of return value.

Usage

prenowiki检查到模板循环:模板:Return/nowiki/pre

Example

prenowiki检查到模板循环:模板:Return/nowiki/pre

Output

检查到模板循环:模板:Return /div /noinclude

Example

Print the current post's title %%% <?php echo get_the_title(); ?> %%%

Simple breadcrumb trail for pages, two levels deep.

<div class='breadcrumb'>
<?php // if there is a parent, display the link
$parent_title = get_the_title($post->post_parent);
if ( $parent_title != the_title(' ', ' ', false) ) {
  echo '<a href=' . get_permalink($post->post_parent)
    . ' ' . 'title=' . $parent_title . '>' . $parent_title
    . '</a> » ';
} 
// then go on to the current page link
?>
<a href='<?php the_permalink() ?>'
rel='bookmark' title='<?php the_title(); ?>'>
<?php the_title(); ?></a> »
</div>

Change Log

Since: 0.71

Source File

get_the_title() is located in onlyincludecodewp-includes/post-template.php/code/onlyinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Template Description

Link to the source code on http://core.trac.wordpress.org/browser/.

Parameters

  1. filename
  2. (option) path to codetag/code (version) or codetrunk/code. This option is only used for a new function.br /Default: codetrunk/code -- trunk is the latest bleeding edge development version of WordPress.

Usage

Link to the stable version: pre检查到模板循环:模板:Trac/pre

Link to trunk: pre检查到模板循环:模板:Trac/pre

/div

wordpress.org.cn.

Related

body_class, next_image_link, next_post_link, next_posts_link, post_class, post_password_required, posts_nav_link, previous_image_link, previous_post_link, previous_posts_link, single_post_title, sticky_class, the_category, the_category_rss, the_content, the_content_rss, the_excerpt, the_excerpt_rss, the_ID, the_meta, the_shortlink, the_tags, the_title, the_title_attribute, the_title_rss, wp_link_pages

includeonlydiv style=clear:both; background-color:#F7F7F7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;See also index of Function Reference and index of Template Tags./div/includeonlynoinclude

Description

This Template is used by Codex:Template Messages.

Usage

pre 检查到模板循环:模板:Message /pre

Result

检查到模板循环:模板:Message

/noinclude

includeonlydiv style=clear:both; background-color:#FAEBD7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;This page is marked as incomplete. You can help Codex by expanding it./div/includeonlynoinclude

Description

This Template is used by Codex:Template Messages.

Usage

pre 检查到模板循环:模板:Message /pre

Result

检查到模板循环:模板:Message

/noinclude