功能:
返回你博客的信息,get_bloginfo()用来获取博客信息
用法:
参数:
$show (字符串string) (可选)你需要输出的信息的关键词。
默认: name
- ‘name‘ – 显示在 设置 > 常规 中设置的“站点标题”。 该数据是从 wp_options 这个数据表中检索到的 “blogname”记录。
- ‘description‘ – 显示在 设置 > 常规 中设置的“副标题”。该数据是从 wp_options 这个数据表中检索到的 “blogdescription” 记录。
- ‘wpurl‘ – 显示在 设置 > 常规 中设置的 “WordPress 地址 (URL)”。该数据是从 wp_options 这个数据表中检索到的 “siteurl” 记录。 可以考虑使用 site_url() 来代替,尤其是在使用 子目录路径方式,而不是使用 子域名 来配置多站点时(bloginfo将返回根网站的URL,而不是子站点的URL)。
- ‘siteurl‘ / ‘url‘ – 显示在 设置 > 常规 中设置的 “站点地址(URL)”)”。该数据是从 wp_options 这个数据表中检索到的 “home”记录。 可以考虑使用 home_url() 代替。
- ‘admin_email’ – 显示在 设置 > 常规 中设置的 “电子邮件地址”。该数据是从 wp_options 这个数据表中检索到的 “admin_email”记录。
- ‘charset’ – 显示在 设置 > 常规 中设置的“页面和feed的编码”。该数据是从 wp_options 这个数据表中检索到的”blog_charset” 记录。(注:3.5.1+好像已经没有这个选项了)
- ‘version’ – 显示你当前使用的 WordPress 版本。该数据是在 wp-includes/version.php 检索到的 $wp_version 这个字段的值。
- ‘html_type’ – 显示WordPress HTML 页面中的内容类型(默认: “text/html”)。该数据可以从 wp_options 这个数据表中检索到的 “html_type” 记录。主题和插件可以通过使用 pre_option_html_type 过滤器覆盖默认值。
- ‘text_direction’ – 显示 WordPress HTML 页面的文本方向。可以考虑使用 is_rtl() 代替。
- ‘language’ – 显示WordPress的语言。
- ‘stylesheet_url’ – 显示当前使用的主题的 CSS文件(通常为 style.css)路径。可以考虑使用 get_stylesheet_uri() 代替。
- ‘stylesheet_directory’ – 显示当前使用的主题的样式表路径。可以考虑使用 get_stylesheet_directory_uri() 代替。
- ‘template_url’ / ‘template_directory’ – 当前主题的 URL 路径 。在子主题中, get_bloginfo(‘template_url’) 和 get_template() 都将返回父主题的目录。可以考虑使用 get_template_directory_uri() (用于父主题目录)或get_stylesheet_directory_uri() (用于子主题目录)代替。
- ‘pingback_url’ – 显示通告文件 XML-RPC 的URL (xmlrpc.php)
- ‘atom_url’ – 显示 Atom feed URL (/feed/atom)
- ‘rdf_url’ – 显示 RDF/RSS 1.0 feed URL (/feed/rfd).
- ‘rss_url’ – 显示 RSS 0.92 feed URL (/feed/rss).
- ‘rss2_url’ – 显示 RSS 2.0 feed URL (/feed).
- ‘comments_atom_url’ – 显示评论的 Atom feed URL (/comments/feed).
- ‘comments_rss2_url’ – 显示评论的 RSS 2.0 feed URL (/comments/feed).
$filter
(字符串 string) (可选)关键字指定如何过滤检索到的数据。
默认: raw
‘display’ – 通过 wptexturize() 函数过滤 $show 的值,然后返回输出给请求者。
‘raw’ – 直接返回 $show 的值。
返回值:
返回相应的博客信息
所在位置:
get_bloginfo() 包含在 wp-includes/general-template.php.
源码:
/**
* Retrieve information about the blog.
*
* Some show parameter values are deprecated and will be removed in future
* versions. These options will trigger the {@see _deprecated_argument()}
* function. The deprecated blog info options are listed in the function
* contents.
*
* The possible values for the 'show' parameter are listed below.
*
* 1. url - Blog URI to homepage.
* 2. wpurl - Blog URI path to WordPress.
* 3. description - Secondary title
*
* The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
* 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
* comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
* feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
*
* @since 0.71
*
* @param string $show Blog info to retrieve.
* @param string $filter How to filter what is retrieved.
* @return string Mostly string values, might be empty.
*/
function get_bloginfo( $show = '', $filter = 'raw' ) {
switch( $show ) {
case 'home' : // DEPRECATED
case 'siteurl' : // DEPRECATED
_deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The %s
option is deprecated for the family of bloginfo()
functions.' ), $show ) . ' ' . sprintf( __( 'Use the %s
option instead.' ), 'url' ) );
case 'url' :
$output = home_url();
break;
case 'wpurl' :
$output = site_url();
break;
case 'description':
$output = get_option('blogdescription');
break;
case 'rdf_url':
$output = get_feed_link('rdf');
break;
case 'rss_url':
$output = get_feed_link('rss');
break;
case 'rss2_url':
$output = get_feed_link('rss2');
break;
case 'atom_url':
$output = get_feed_link('atom');
break;
case 'comments_atom_url':
$output = get_feed_link('comments_atom');
break;
case 'comments_rss2_url':
$output = get_feed_link('comments_rss2');
break;
case 'pingback_url':
$output = site_url( 'xmlrpc.php' );
break;
case 'stylesheet_url':
$output = get_stylesheet_uri();
break;
case 'stylesheet_directory':
$output = get_stylesheet_directory_uri();
break;
case 'template_directory':
case 'template_url':
$output = get_template_directory_uri();
break;
case 'admin_email':
$output = get_option('admin_email');
break;
case 'charset':
$output = get_option('blog_charset');
if ('' == $output) $output = 'UTF-8';
break;
case 'html_type' :
$output = get_option('html_type');
break;
case 'version':
global $wp_version;
$output = $wp_version;
break;
case 'language':
$output = get_locale();
$output = str_replace('_', '-', $output);
break;
case 'text_direction':
//_deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The %s
option is deprecated for the family of bloginfo()
functions.' ), $show ) . ' ' . sprintf( __( 'Use the %s
function instead.' ), 'is_rtl()' ) );
if ( function_exists( 'is_rtl' ) ) {
$output = is_rtl() ? 'rtl' : 'ltr';
} else {
$output = 'ltr';
}
break;
case 'name':
default:
$output = get_option('blogname');
break;
}
$url = true;
if (strpos($show, 'url') === false &&
strpos($show, 'directory') === false &&
strpos($show, 'home') === false)
$url = false;
if ( 'display' == $filter ) {
if ( $url ) {
/**
* Filter the URL returned by get_bloginfo().
*
* @since 2.0.5
*
* @param mixed $output The URL returned by bloginfo().
* @param mixed $show Type of information requested.
*/
$output = apply_filters( 'bloginfo_url', $output, $show );
} else {
/**
* Filter the site information returned by get_bloginfo().
*
* @since 0.71
*
* @param mixed $output The requested non-URL site information.
* @param mixed $show Type of information requested.
*/
$output = apply_filters( 'bloginfo', $output, $show );
}
}
return $output;
}
示例:
'.$blog_title.'';
?>
相关函数:
感觉本站内容不错,读后有收获?小额赞助
还可以分享文章给好友:
这函数用的挺多的~