Quantcast
Channel: WP MEMO »ウィジェット
Viewing all articles
Browse latest Browse all 3

テーマをウィジェットに対応させる

$
0
0

Word Pressのテーマによってはウィジェットに対応していない場合があります。
その場合はfunctions.php、ウィジェットを使用するテンプレート(sidebar.phpなど)への記述が必要となります。

functions.php

<?php
if ( function_exists('register_sidebar') ) {
	register_sidebar(array(
		'before_widget' => '<li id="%1$s" class="widget %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h2 class="widgettitle">',
		'after_title' => '</h2>',
	));
}
?>

ウィジェットを表示されたい場所に下記のコードを記述します。

sidebar.phpなど

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php endif; ?>

なお、出力されるHTML、class名を変更したい場合は、
上記のfunctions.phpを修正していきます。
例えば出力されるウィジェットのタイトルを、

「class名は無しで、h3タグにしたい」

といった場合は以下のように記述します。

functions.php

<?php
if ( function_exists('register_sidebar') ) {
	register_sidebar(array(
		'before_widget' => '<li id="%1$s" class="widget %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3>',
		'after_title' => '</h3>',
	));
}
?>

Viewing all articles
Browse latest Browse all 3

Trending Articles