WORDPRESS函数:BLOGINFO(显示博客信息)

描述

显示你的博客信息,大部分都是显示WordPress管理界面的 用户资料 和 常规设置 中的信息。它可以在模板文件的任何地方使用。一般 bloginfo() 都是用来直接在浏览器中输出内容的。如果你需要在PHP中返回值的话,那么请用 get_bloginfo()。

用法

<?php bloginfo( $show ); ?>

参数

$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).

例子

《显示博客标题

在 <h1> 标签中显示博客标题

<h1><?php bloginfo('name'); ?></h1>

显示带链接的博客标题

显示一个带站点链接的博客标题

<a href="<?php bloginfo('url'); ?>" title="<?php bloginfo('name'); ?>"><?php bloginfo('name'); ?></a>

显示字符集

显示你博客设置的字符集(例如“UTF-8”)

<p>Character set: <?php bloginfo('charset'); ?> </p>

显示博客描述

显示在 设置 > 常规 中设置的“副标题”

<p><?php bloginfo('description'); ?> </p>

示例输出

从 2.7 版开始,在主机中,站点地址(URL) 显示的是 http://www.example.com/home, WordPress 地址 (URL) 是安装在 http://www.example.com/home/wp。

需要注意的是,这些链接是不带最后的斜线的!

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 (已弃用!使用 url 替代) 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 (已弃用!使用 url 替代) 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

所在文件

bloginfo() 包含在 wp-includes/general-template.php。 相关函数

get_bloginfo() 目录URL标签

WordPress的目录:

home_url() 首页URL http://www.example.com site_url() 网站目录URL http://www.example.com 或 http://www.example.com/wordpress admin_url() 管理目录URL http://www.example.com/wp-admin includes_url() 包含目录URL http://www.example.com/wp-includes content_url() 文章目录URL http://www.example.com/wp-content plugins_url() 插件目录URL http://www.example.com/wp-content/plugins theme_url() 主题目录URL http://www.example.com/wp-content/themes wp_upload_dir() 上传目录URL (返回一个数组) http://www.example.com/wp-content/uploads 英文:http://codex.wordpress.org/Template_Tags/bloginfo

翻译:倡萌@WordPress大学

Comments: 2

「人生在世,留句话给我吧」

提交评论