mk-webwork codenote

footer or sidbarなどに定義したオリジナルウェジットを埋め込む

functions.phpにて、register_sidebar()を設定します。

add_action( 'widgets_init', 'theme_slug_widgets_init' ); 
function theme_slug_widgets_init() {
    $args = array(
      'name' => __( 'コンテンツ下部右ウィジェット', 'find-ochanomizu' ),//わかりやすい表示名+テーマテキストドメイン
          'id' => 'content-footer', //ID名はユニーク
           );
     register_sidebar( $args );
}

//デフォルト
array(
	'name'          => __( 'Sidebar name', 'theme_text_domain' ),
	'id'            => 'unique-sidebar-id', 
	'description'   => '',
	'class'         => '',
	'before_widget' => '<li id="%1$s" class="widget %2$s">',
	'after_widget'  => '</li>',
	'before_title'  => '<h2 class="widgettitle">',
	'after_title'   => '</h2>' );

外観にウェジット項目が追加される。

ウェジットから入れたい項目を追加していく

footer or sidebar など呼び出したい場所に記述。

<?php if ( is_active_sidebar( 'content-footer' ) ) : ?> //ウィジェットがアクティブの場合に表示する
<ul id="">
<?php dynamic_sidebar( 'content-footer' ); ?> //dynamic_sidebarでオリジナルウェジットを呼び出す(funktions.phpで定義したID名))
</ul>
<?php endif; ?>
← もどる