dynamic_sidebar

Sponsored Link

この関数は、サイドバーのマークアップで出力された、ソート内でコールバックされた有効な各ウィジェットを呼び出します。1つ以上のサイドバーがある場合、出力したいサイドバーの名前あるいは数字の関数を取得する必要があります。この関数は、成功の場合はtrueを、失敗の場合はfalseを返します。

静的サイドバーを表示するかを決定するために使用すべき戻り値です。
これにより、あなたのテーマがウィジェットプラグインが有効でない時でさえ良いように見えます。

サイドバーが数字によって登録された場合、それらは数字で取得すべきです。それらを登録された時名前を持っていた場合、それらを取得するために名前を使用をします。

Sponsored Link

This function calls each of the active widget callbacks in order, which prints the markup for the sidebar. If you have more than one sidebar, you should give this function the name or number of the sidebar you want to print. This function returns true on success and false on failure.

The return value should be used to determine whether to display a static sidebar. This ensures that your theme will look good even when the Widgets plug-in is not active.

If your sidebars were registered by number, they should be retrieved by number. If they had names when you registered them, use their names to retrieve them.

dynamic_sidebarのファンクションタグ使用方法

<?php dynamic_sidebar( $index ); ?> 

dynamic_sidebarのパラメーター

index

(integer/string) (optional) ダイナミックサイドバーの名前とIDです。

(integer/string) (optional) Name or ID of dynamic sidebar.

Default: 1

戻り値

(boolean) Trueは、ウィジェットのサイドバーが発見された場合に呼ばれる。 falseの場合、見つからないまたは呼び出されません。

(boolean)
True, if widget sidebar was found and called. False if not found or not called.

ここは、このファンクションの使用を推奨しています:

Here is the recommended use of this function:

<ul id="sidebar">
<?php if ( !dynamic_sidebar() ) : ?>
   <li>{static sidebar item 1}</li>
   <li>{static sidebar item 2}</li>
<?php endif; ?>
</ul>
<ul id="sidebar">
   <?php dynamic_sidebar( 'Right Sidebar' ); ?>
</ul>

“Twenty Ten”テーマ (3.0+)内では、

in the “Twenty Ten” theme (3.0+)

  • wp-content/themes/twentyten/sidebar.php
  • wp-content/themes/twentyten/sidebar-footer.php

マルチのサイドバー

名前(もし文字列を指定された場合)かID(もし整数を指定された場合)のいづれかによって特定のサイドバーを読み込むことができます。例えば、dynamic_sidebar(‘top_menu’)は、register_sidebar(array(‘name’=>’top_menu’,))と共に登録する親サイドバーだろう。

IDを使用する事は、サイドバー( dynamic_sidebar(1) )に名付ける必要がないという点において簡単ですが、ウィジェットの管理パネルやfunctions.phpファイルを見もせずに理解する事が難しいため、コードが読みにくく作られています。IDの1で開始する事に注意してください。

register_sidebar()のWordPress関数内に独自のID値を名付ける場合は、コードの可読性を高めるかもしれません。IDはすべて小文字英数字の文字列であるべきであり、空白を含めないようにしてください。- と _ の文字列を使用することも出来ます。IDは任意である必要があり、サイドバー名を一致させることはできません。独自IDを使用することはサイドバー名の翻訳をすることができます。

You can load a specific sidebar by either their name (if given a string) or ID (if given an integer). For example, dynamic_sidebar(‘top_menu’) will present a sidebar registered with register_sidebar(array(‘name’=>’top_menu’,)).

Using ID’s ( dynamic_sidebar(1) ) is easier in that you don’t need to name your sidebar, but they are harder to figure out without looking into your functions.php file or in the widgets administration panel and thus make your code less readable. Note that ID’s begin at 1.

If you name your own ID values in the register_sidebar() WordPress function, you might increase readability of the code. The ID should be all lowercase alphanumeric characters and not contain white space. You can also use the – and _ characters. IDs must be unique and cannot match a sidebar name. Using your own IDs can also make the sidebar name translatable.

// $text_domainのための有効な値についてthe __() のWordPressのファンクションタグを参照してください。See the __() WordPress function for valid values for $text_domain.
register_sidebar( array(
    'id'          => 'top-menu',
    'name'        => __( 'Top Menu', $text_domain ),
    'description' => __( 'This sidebar is located above the age logo.', $text_domain ),
) );

これはIDを使用しているdynamic_sidebar( ‘top-menu’ )の使用を許可して、有効にします。

This allows the use of dynamic_sidebar( ‘top-menu’ ) which uses an ID and is readable.

変更ログ

Since: 2.2.0

ソースファイル

dynamic_sidebar()は、wp-includes/widgets.php内に位置しています。

dynamic_sidebar() is located in wp-includes/widgets.php.

  • WordPress theme flexibility with dynamic sidebars
  • The meaning of “spitting out” widgets
  • Customizing the display of widgets on each page.

関連ファンクションタグ

Sidebars: is_active_sidebar(), register_sidebars(), register_sidebar(), unregister_sidebar(), is_dynamic_sidebar(), dynamic_sidebar(), wp_register_sidebar_widget(), wp_unregister_sidebar_widget(), wp_get_sidebars_widgets(), wp_set_sidebars_widgets()

Widgets: is_active_widget(), the_widget(), register_widget(), unregister_widget(), wp_register_widget_control(), wp_unregister_widget_control(), wp_convert_widget_settings(), wp_get_widget_defaults(), wp_widget_description()

Sponsored Link