當(dāng)前位置:首頁>WordPress建站>WordPress開發(fā)>WordPress函數(shù):bloginfo(顯示博客信息)

WordPress函數(shù):bloginfo(顯示博客信息)

描述

顯示你的博客信息,大部分都是顯示W(wǎng)ordPress管理界面的 用戶資料 和 常規(guī)設(shè)置 中的信息。它可以在模板文件的任何地方使用。一般 bloginfo() 都是用來直接在瀏覽器中輸出內(nèi)容的。如果你需要在PHP中返回值的話,那么請用 get_bloginfo()。

用法

<?php bloginfo( $show ); ?> 

參數(shù)

$show (字符串string) (可選)你需要輸出的信息的關(guān)鍵詞。

       默認: name

  • name‘ – 顯示在 設(shè)置 > 常規(guī) 中設(shè)置的“站點標(biāo)題”。 該數(shù)據(jù)是從 wp_options 這個數(shù)據(jù)表中檢索到的 "blogname"記錄。
  • description‘ – 顯示在 設(shè)置 > 常規(guī) 中設(shè)置的“副標(biāo)題”。該數(shù)據(jù)是從 wp_options 這個數(shù)據(jù)表中檢索到的 "blogdescription" 記錄。
  • wpurl‘ – 顯示在 設(shè)置 > 常規(guī) 中設(shè)置的 “WordPress 地址 (URL)”。該數(shù)據(jù)是從 wp_options 這個數(shù)據(jù)表中檢索到的 "siteurl" 記錄。 可以考慮使用 site_url() 來代替,尤其是在使用 子目錄路徑方式,而不是使用 子域名 來配置多站點時(bloginfo將返回根網(wǎng)站的URL,而不是子站點的URL)。
  • siteurl‘ / ‘url‘ – 顯示在 設(shè)置 > 常規(guī) 中設(shè)置的 “站點地址(URL)”)”。該數(shù)據(jù)是從 wp_options 這個數(shù)據(jù)表中檢索到的 "home"記錄。 可以考慮使用 home_url() 代替。
  • ‘admin_email’ – 顯示在 設(shè)置 > 常規(guī) 中設(shè)置的 “電子郵件地址”。該數(shù)據(jù)是從 wp_options 這個數(shù)據(jù)表中檢索到的 "admin_email"記錄。
  • ‘charset’ – 顯示在 設(shè)置 > 常規(guī) 中設(shè)置的“頁面和feed的編碼”。該數(shù)據(jù)是從 wp_options 這個數(shù)據(jù)表中檢索到的"blog_charset" 記錄。(注:3.5.1+好像已經(jīng)沒有這個選項了)
  • ‘version’ – 顯示你當(dāng)前使用的 WordPress 版本。該數(shù)據(jù)是在 wp-includes/version.php 檢索到的 $wp_version  這個字段的值。
  • ‘html_type’ – 顯示W(wǎng)ordPress HTML 頁面中的內(nèi)容類型(默認: "text/html")。該數(shù)據(jù)可以從 wp_options 這個數(shù)據(jù)表中檢索到的 "html_type" 記錄。主題和插件可以通過使用 pre_option_html_type 過濾器覆蓋默認值。
  • ‘text_direction’ – 顯示 WordPress HTML 頁面的文本方向。可以考慮使用 is_rtl() 代替。
  • ‘language’ – 顯示W(wǎng)ordPress的語言。
  • ‘stylesheet_url’ – 顯示當(dāng)前使用的主題的 CSS文件(通常為 style.css)路徑。可以考慮使用 get_stylesheet_uri() 代替。
  • ‘stylesheet_directory’ – 顯示當(dāng)前使用的主題的樣式表路徑。可以考慮使用 get_stylesheet_directory_uri() 代替。
  • ‘template_url’ / ‘template_directory’ – 當(dāng)前主題的 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).

例子

顯示博客標(biāo)題

在 <h1> 標(biāo)簽中顯示博客標(biāo)題

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

顯示帶鏈接的博客標(biāo)題

顯示一個帶站點鏈接的博客標(biāo)題

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

顯示字符集

顯示你博客設(shè)置的字符集(例如“UTF-8”)

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

顯示博客描述

顯示在 設(shè)置 > 常規(guī) 中設(shè)置的“副標(biāo)題”

<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。

相關(guān)函數(shù)

get_bloginfo()

目錄URL標(biāo)簽

WordPress的目錄:

  • home_url() 首頁URL http://www.example.com
  • site_url() 網(wǎng)站目錄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 (返回一個數(shù)組) http://www.example.com/wp-content/uploads

英文:http://codex.wordpress.org/Template_Tags/bloginfo

翻譯:倡萌@WordPress大學(xué)

聲明:本站所有文章,如無特殊說明或標(biāo)注,均為本站原創(chuàng)發(fā)布。任何個人或組織,在未征得本站同意時,禁止復(fù)制、盜用、采集、發(fā)布本站內(nèi)容到任何網(wǎng)站、書籍等各類媒體平臺。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進行處理。

給TA打賞
共{{data.count}}人
人已打賞
歡迎關(guān)注WordPress大學(xué)公眾號 WPDAXUE
WordPress開發(fā)

WordPress函數(shù):comments_template(獲取評論模板)

2013-4-5 7:50:00

WordPress開發(fā)

WordPress函數(shù):bloginfo_rss

2013-4-7 9:29:46

8 條回復(fù) A文章作者 M管理員
  1. 我有個問題請教,win主機,上傳了httpd,支持了偽靜態(tài),屏蔽了index.php,設(shè)置了固定連接。但是在點擊回復(fù)某個評論時,鏈接里又出現(xiàn)了index.php/,導(dǎo)致404,這是咋回事? ?

    • 我只想說,放棄你的windows主機吧,這是最明智的

  2. url 打成 uri 了,不用謝,我是雷鋒

    • 好吧,是我錯了

  3. 學(xué)習(xí)了

  4. 老大 剛才沒表達清楚 具體如下
    <a href="<?php bloginfo(‘siteurl’);?>">xxx</a> 想把<?php bloginfo(‘siteurl’);?> 換成當(dāng)前分類目錄鏈接

  5. 倡萌 當(dāng)前鏈接如何表示呢

  6. 原來這個我認為最簡單的函數(shù)這么神奇

?
個人中心
購物車
優(yōu)惠劵
今日簽到
有新私信 私信列表
搜索

濉溪县| 高安市| 通城县| 洱源县| 山阳县| 扎赉特旗| 环江| 福海县| 乌兰县| 常山县| 芦溪县| 理塘县| 新源县| 班戈县| 葵青区| 类乌齐县| 高安市| 西城区| 清水河县| 萝北县| 玉树县| 东源县| 宁乡县| 宿州市| 尼勒克县| 虎林市| 三河市| 临漳县| 本溪| 环江| 无为县| 大洼县| 内黄县| 长治县| 潼南县| 铜陵市| 桑植县| 同心县| 清河县| 古田县| 泊头市|