Function Reference/get bloginfo

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

wordpress.org.cn

Description

Returns information about your site which can then be used elsewhere in your PHP code. This function, as well as bloginfo(), can also be used to display your site information anywhere within a template file.

Usage

%%% <?php $bloginfo = get_bloginfo( $show, $filter ); ?> %%%

Parameters

tt$show/tt
(string) (Optional) Keyword naming the information you want.
Default: namenoinclude

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

  • 'name' - Returns the "Site Title" set in Settings > General. This data is retrieved from the "blogname" record in the wp_options table.
  • 'description' - Returns the "Tagline" set in Settings > General. This data is retrieved from the "blogdescription" record in the wp_options table.
  • 'wpurl' - Returns the "WordPress address (URL)" set in Settings > General. This data is retrieved from the "siteurl" record in the wp_options table. Consider using site_url() instead, especially for multi-site configurations using paths instead of subdomains (it will return the root site not the current sub-site).
  • 'url' - Returns the "Site address (URL)" set in Settings > General. This data is retrieved from the "home" record in the wp_options table. Equivalent to home_url().
  • 'admin_email' - Returns the "E-mail address" set in Settings > General. This data is retrieved from the "admin_email" record in the wp_options table.
  • 'charset' - Returns the "Encoding for pages and feeds" set in Settings > Reading. This data is retrieved from the "blog_charset" record in the wp_options table.
  • 'version' - Returns the WordPress Version you use. This data is retrieved from the $wp_version variable set in onlyincludecodewp-includes/version.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.

  • 'html_type' - Returns the Content-Type of WordPress HTML pages (default: "text/html"). This data is retrieved from the "html_type" record in the wp_options table. Themes and plugins can override the default value using the pre_option_html_type filter.
  • 'text_direction' - Returns the Text Direction of WordPress HTML pages. Consider using is_rtl() instead.
  • 'language' - Returns the language of WordPress.
  • 'stylesheet_url' - Returns the primary CSS (usually style.css) file URL of the active theme. Consider using get_stylesheet_uri() instead.
  • 'stylesheet_directory' - Returns the stylesheet directory URL of the active theme. (Was a local path in earlier WordPress versions.) Consider using get_stylesheet_directory_uri() instead.
  • 'template_url' / 'template_directory' - URL of the active theme's directory ('template_directory' was a local path before 2.6; see get_theme_root() and get_template() for hackish alternatives.) Within child themes, both get_bloginfo('template_url') and get_template() will return the parent theme directory. Consider using get_template_directory_uri() instead (for the parent template directory) or get_stylesheet_directory_uri() (for the child template directory).
  • 'pingback_url' - Returns the Pingback XML-RPC file URL (xmlrpc.php).
  • 'atom_url' - Returns the Atom feed URL (/feed/atom).
  • 'rdf_url' - Returns the RDF/RSS 1.0 feed URL (/feed/rfd).
  • 'rss_url' - Returns the RSS 0.92 feed URL (/feed/rss).
  • 'rss2_url' - Returns the RSS 2.0 feed URL (/feed).
  • 'comments_atom_url' - Returns the comments Atom feed URL (/comments/feed).
  • 'comments_rss2_url' - Returns the comments RSS 2.0 feed URL (/comments/feed).
  • 'siteurl' - Deprecated since version 2.2. Use home_url(), or get_bloginfo('url').
  • 'home' - Deprecated since version 2.2. Use home_url(), or get_bloginfo('url').
tt$filter/tt
(string) (Optional) Keyword specifying how to filter what is retrieved.
Default: rawnoinclude

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

  • 'display' - Passes the value of $show through the wptexturize() function before returning it to caller.
  • 'raw' - Returns the value of $show as is.

Examples

Default Usage

The default usage assigns your blog's title to the variable $blog_title.

 <?php $blog_title = get_bloginfo(); ?>

Blog Title

This example assign your blog's title to the variable $blog_title. This returns the same result as the default usage.

 <?php $blog_title = get_bloginfo('name'); ?>

Blog Tagline

Using this example:

 <?php echo 'Your Blog Tagline is: ' . get_bloginfo ( 'description' );  ?><br />

results in this being displayed on your blog:

 Your Blog Tagline is: All things WordPress

Network Tagline

Using this example, you can obtain the name and description for the network home:

 <?php
 switch_to_blog(1);
 $site_title = get_bloginfo( 'name' );
 $site_url = network_site_url( '/' );
 $site_description = get_bloginfo( 'description' );
 restore_current_blog();
 echo 'The Network Home URL is: ' . $site_url;
 echo 'The Network Home Name is: ' . $site_title;
 echo 'The Network Home Tagline is: ' . $site_description;  
?>

results in this being displayed on your blog:

 The Network Home URL is: http://example.com/
 The Network Home Name is: Example
 The Network Home Tagline is: The example site

Template Directory

Returns template directory URL to the active theme.

Example output

From version 2.7. On host example, the Blog address (URL) is shown at http://www.example.com/home, and the WordPress address (URL) is installed at http://www.example.com/home/wp.

Note that directory URLs are missing trailing slashes.

admin_email          = admin@example.com
atom_url             = http://www.example.com/home/feed/atom
charset              = UTF-8
comments_atom_url    = http://www.example.com/home/comments/feed/atom
comments_rss2_url    = http://www.example.com/home/comments/feed
description          = Just another WordPress blog
home                 = http://www.example.com/home (DEPRECATED! use url option instead)
html_type            = text/html
language             = en-US
name                 = Testpilot
pingback_url         = http://www.example.com/home/wp/xmlrpc.php
rdf_url              = http://www.example.com/home/feed/rdf
rss2_url             = http://www.example.com/home/feed
rss_url              = http://www.example.com/home/feed/rss
siteurl              = http://www.example.com/home (DEPRECATED! use url option instead)
stylesheet_directory = http://www.example.com/home/wp/wp-content/themes/largo
stylesheet_url       = http://www.example.com/home/wp/wp-content/themes/largo/style.css
template_directory   = http://www.example.com/home/wp/wp-content/themes/largo
template_url         = http://www.example.com/home/wp/wp-content/themes/largo
text_direction       = ltr
url                  = http://www.example.com/home
version              = 3.5
wpurl                = http://www.example.com/home/wp

Change Log

Since: 0.71

Source File

get_bloginfo() is located in onlyincludecodewp-includes/general-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

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