get_bloginfo() WP 0.71

Отримує інформацію про сайт із налаштувань.

Це копія bloginfo() , тільки ця функція отримує результат змінну, а не виводить його на екран.

Основа для:
bloginfo()
1 раз – 0.00019 сек
(швидко) | 50000 разів – 6.07 сек
(швидко)

Хуки з функції

Повертає

Строку. Вказані дані.

Використання

get_bloginfo($ show, $ filter);
$show
(рядок)
Ім’я параметра інформацію про яке потрібно отримати


За замовчуванням: name (назва блогу)
$filter
(рядок)
Назва фільтра через який потрібно проганяти інформацію, що виводиться. Можливо:
displayабо
raw. Якщо вказано display, результат фільтрується через фільтр
bloginfo.


За замовчуванням: ‘raw’

Приклади

0

#1 Поля, які можна вказати в $show

Імена які можна передати функції в параметрі $ show і те, що в результаті вона виведе:

ОпціяОпис
nameНазивання сайту:Настройки > Основные
descriptionОпис сайту:Настройки > Основные
wpurlУРЛ сайту (адмінки): Настройки > Основные. Дані беруться з опції “siteurl” wp_options . Псевдонім site_url() .
urlУРЛ сайту (фронту): Настройки > Основные. Дані беруться з опції “home” wp_options . Псевдонім home_url()
admin_emailEmail адміністратора: Настройки > Основные. Дані беруться з “admin_email” у таблиці wp_options .
charsetКодування блоґу. Дані беруться з “blog_charset” у таблиці wp_options. З версії 3.5 кодування блогу не налаштовується з адмінки і цей параметр завжди дорівнює UTF-8.
versionВерсія WP. Дані беруться зі змінної $wp_version .
html_typeТип контенту HTML сторінки (за замовчуванням: “text/html”). Дані беруться з “html_type” у таблиці wp_options. Теми та плагіни можуть переписати цю змінну через хук pre_option_html_type.
languageМова сайту (локаль), наприклад, ru-RU .
stylesheet_urlУРЛ на CSS стилі сайту (зазвичай це файл style.css ). Псевдонім get_stylesheet_uri() .
stylesheet_directoryУРЛ на директорію теми, де є файл стилів. Псевдонім get_stylesheet_directory_uri() .
template_directory
template_url
УРЛ на директорію теми. Псевдонім get_template_directory_uri() .
pingback_urlУРЛ файл пінгів XML-RPC (xmlrpc.php).
atom_urlУРЛ Atom фіда (/feed/atom).
rdf_urlУРЛ RDF/RSS 1.0 фіда (/feed/rfd).
rss_urlУРЛ RSS 0.92 фіда (/feed/rss).
rss2_urlУРЛ RSS 2.0 фіда (/feed).
comments_atom_urlУРЛ Atom фіда коментарів (/comments/feed).
comments_rss2_urlУРЛ RSS 2.0 фіда коментарів (/comments/feed).
homeЗаборонено з версії 2.2. Використовуйте home_url() .
siteurlЗаборонено з версії 2.2. Використовуйте site_url() .

Ті самі параметри зі значеннями:

admin_email = [email protected]
atom_url = http://example.ru/feed/atom
charset = UTF-8
comments_atom_url = http://example.ru/comments/feed/atom
comments_rss2_url = http://example.ru/comments/feed
description = Just another WordPress blog
html_type = text/html
language = en-US
name = Testpilot
pingback_url = http://example.ru/xmlrpc.php
rdf_url = http://example.ru/feed/rdf
rss2_url = http://example.ru/feed
rss_url = http://example.ru/feed/rss
stylesheet_directory = http://example.ru/wp-content/themes/largo
stylesheet_url = http://example.ru/wp-content/themes/largo/style.css
template_directory = http://example.ru/wp-content/themes/largo
template_url = http://example.ru/wp-content/themes/largo
text_direction = ltr
url = http://example.ru
version = 2.7
wpurl = http://example.ru

Дефолтне використання. Передамо назву блогу в змінну $blog_title , щоб потім використовувати змінну десь.

<?php $blog_title = get_bloginfo(); ?>
//використовуємо змінну
<?php echo $blog_title ?>

Те саме буде повернено функцією, якщо написати так:

<?php $blog_title = get_bloginfo('name'); ?>

Можливий приклад використання функції у шаблоні WordPress:

<?php echo 'Короткий опис блогу: ' . get_bloginfo('description', 'display'); ?><br />
//в результаті на екрані з'явиться такий напис: Короткий опис блогу: <тут опис>

нотатки

  • Global. Рядок. $wp_version The WordPress version string.

список змін

З версії 0.71Введено.

get bloginfo WP 6.0.2

function get_bloginfo( $show = '', $filter = 'raw' ) { switch ($show) { case 'home': // Deprecated. case 'siteurl': // Deprecated. _deprecated_argument( __FUNCTION__, '2.2.0', sprintf( /* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument. */ __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ), '<code>' . $ show . '</code>', '<code>bloginfo()</code>', '<code>url</code>' ) ); // Intentional fall-through to be handled by the 'url' case. 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': /* * translators: Translate this to the correct language tag for your locale, * see https://www.w3.org/International/articles/language-tags/ for reference. * Do not translate у вашу own language. */ $output = __( 'html_lang_attribute'); if ( 'html_lang_attribute' === $output || preg_match( '/[^a-zA-Z0-9-]/', $output ) ) { $output = determine_locale(); $output = str_replace( '_', '-', $output ); } break; case 'text_direction': _deprecated_argument( __FUNCTION__, '2.2.0', sprintf( /* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name. */ __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ), '<code>' . $ show . '</code>', '<code>bloginfo()</code>', '<code>is_rtl()</code>' ) ); 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 ) { /** * Filters the URL returned by get_bloginfo(). * * @ Since 2.0.5 * * @param string $output URL-адреса повернулася до bloginfo(). * @param string $show Type of information requested. */ $output = apply_filters( 'bloginfo_url', $output, $show); } else { /** * Filters the site information returned by get_bloginfo(). * * @ Since 0.71 * * @param mixed $output Захищена URL-адреса веб-сайту. * @param string $show Type of information requested. */ $output = apply_filters( 'bloginfo', $output, $show ); } } return $output; }

Залишити відповідь

Ваша e-mail адреса не оприлюднюватиметься. Обов’язкові поля позначені *