wordpress函数:bloginfo()函数用法

  • 内容
  • 评论
  • 相关

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

用法

<?php bloginfo( $param ); ?>

参数

$param 为字符串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)
stylesheet_directory 显示当前使用的主题的样式表路径。可以考虑使用 get_stylesheet_directory_uri() 代替。
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>

注意:以下链接是不带最后的斜线的!

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

IT技术资料分享-个人整理自互联网 本文整理自互联网 如有侵权联系小编删除处理。

 

上一篇: 下一篇:
关注本站微信公众号


仍未解决?点击远程协助
win10纯净版系统安装教程
关闭
关注本站

扫一扫,关注本站微信公众号