Quantcast
Channel: 札幌・ホームページ制作&広告制作の株式会社ループス「Loops」 »● buddypress
Viewing all articles
Browse latest Browse all 6

buddypressカスタマイズ手帳6:複数のウィジェットエリアを追加して、表示する方法。

$
0
0

ウィジェット項目の間に、バナースペースなどを設けたいなぁ〜と思ったら、

そのウィジェットをバラして表示したくなりますよね。

今回は、buddypressでウィジェットエリアを複数追加する方法と、

その表示方法についてのお話です。

ウィジェットは、管理画面の 「外観」>「ウィジェット」 のページにあります。

その中のウィジェットエリアをさらに増やしてみることにします。

 

 例えば新たに作成したサイドバー(sidebar-right.php)に

  2つのウィジェットエリアを設けるとします。

  この場合は、子テーマの「fanction.php」に以下を記述します。

//+++++++++++++++++++++++++++++++++++++++++
//ウィジェットエリアの追加
if ( !function_exists( 'bp_dtheme_widgets_init' ) ) :
function bp_dtheme_widgets_init() {

	register_sidebar( array(
		'name' => __( 'First sidebar right', 'buddypress' ),
		'id' => 'first-sidebar-right-widget-area',
		'description' => __( 'first sidebar right widget area', 'buddypress' ),
		'before_widget' => '<li id="%1$s" class="widget %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widgettitle">',
		'after_title' => '</h3>',
	) );

	register_sidebar( array(
		'name' => __( 'Second sidebar right', 'buddypress' ),
		'id' => 'second-sidebar-right-widget-area',
		'description' => __( 'second sidebar right widget area', 'buddypress' ),
		'before_widget' => '<li id="%1$s" class="widget %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widgettitle">',
		'after_title' => '</h3>',
	) );

}
add_action( 'widgets_init', 'bp_dtheme_widgets_init' );
endif;

※もし、デフォルト(親テーマ)の「fanction.php」とケンカするようでしたら、

デフォルト(親テーマ)「fanction.php」のほうに直接記述します。

 

管理画面の外観>ウィジェットページを確認すると下の画像のようになり、

2つのウィジェットエリアが追加されているのがわかります。

ウィジェット

 

 表示したいsidebar-right.phpの任意の箇所に、

  呼び出しコードを記述します。

<!---First sidebar right--->
<?php if ( is_active_sidebar( 'first-sidebar-right-widget-area' ) ) : ?>
<div id="widgetR_BOX" role="complementary">

   <?php if ( is_active_sidebar( 'first-sidebar-right-widget-area' ) ) : ?>
   <div id="widgetR" class="widgetR-area">
      <ul class="xoxo">
      <?php dynamic_sidebar( 'first-sidebar-right-widget-area' ); ?>
      </ul>
   </div>
   <?php endif; ?>

<div class="clear"></div>
</div>
<?php endif; ?>

<!---Second sidebar right--->
<?php if ( is_active_sidebar( 'second-sidebar-right-widget-area' ) ) : ?>
<div id="widgetR_BOX" role="complementary">

   <?php if ( is_active_sidebar( 'second-sidebar-right-widget-area' ) ) : ?>
   <div id="widgetR" class="widgetR-area">
      <ul class="xoxo">
      <?php dynamic_sidebar( 'second-sidebar-right-widget-area' ); ?>
      </ul>
   </div>
   <?php endif; ?>

<div class="clear"></div>
</div>
<?php endif; ?>

以上で無事ウィジェットエリアが追加され、表示されます。

 

 

 


Viewing all articles
Browse latest Browse all 6

Trending Articles