該標籤顯示用戶博客的相關信息,這些信息通常來自用戶在WordPress網站後臺“我的配置”和“設置>常規”菜單中填寫的內容。該標籤可以用在頁面模板的任何區域內,且該標籤總是將結果輸出給瀏覽器。如果用戶需要將輸出內容用在PHP中,請使用get_bloginfo()。
描述
顯示你的博客信息,大部分都是顯示WordPress管理界面的 用戶資料 和 常規設置 中的信息。它可以在模板文件的任何地方使用。一般 bloginfo() 都是用來直接在瀏覽器中輸出內容的。如果你需要在PHP中返回值的話,那麼請用 get_bloginfo()。
用法
1 | <?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> 標籤中顯示博客標題
1 | <h1><?php bloginfo('name');?></h1> |
顯示帶鏈接的博客標題
顯示一個帶站點鏈接的博客標題
1 | <a href="<?php bloginfo('url');?>" title="<?php bloginfo('name');?>"><?php bloginfo('name');?></a> |
顯示字符集
顯示你博客設置的字符集(例如“UTF-8”)
1 | <p>Character set: <?php bloginfo('charset');?> </p> |
顯示博客描述
顯示在 設置 > 常規 中設置的“副標題”
1 | <p><?php bloginfo('description');?> </p> |
示例輸出
從 2.7 版開始,在主機中,站點地址(URL) 顯示的是 http://www.example.com/home, WordPress 地址 (URL) 是安裝在 http://www.example.com/home/wp。
需要注意的是,這些鏈接是不帶最後的斜線的!
admin_email = [email protected] 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