default で検索結果のページにサイドバーを表示させたい
-
返信有難うございます。
3カラムは default の functions.php の以下の部分をコメントアウトして
/*if ( function_exists(‘register_sidebar’) ) {
register_sidebar(array(
‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ”,
‘before_title’ => ‘<h2 class=”widgettitle”>’,
‘after_title’ => ‘</h2>’,
));
}*/
その下に以下のコードを入れました。
if ( function_exists(‘register_sidebar’) ) {
register_sidebar(array(
‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h2 class=”widgettitle”>’,
‘after_title’ => ‘</h2>’,
));
register_sidebar(array(
‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h2 class=”widgettitle”>’,
‘after_title’ => ‘</h2>’,
));
}
それから sidebar.php のコードをコピーしてそのまま最終行に貼り付け以下の様にしました。
<?php
/**
* @package WordPress
* @subpackage Default_Theme
*/
?>
<div id=”sidebar” role=”complementary”>-
<?php /* Widgetized sidebar, if you have the plugin installed. */
- <?php get_search_form(); ?>
- <h2><?php _e(‘Author’, ‘kubrick’); ?></h2>
<p>A little something about you, the author. Nothing lengthy, just an overview.</p> -
<?php /* If this is a 404 page */ if (is_404()) { ?>
<?php /* If this is a category archive */ } elseif (is_category()) { ?>
<p><?php printf(__(‘You are currently browsing the archives for the %s category.’, ‘kubrick’), single_cat_title(”, false)); ?></p><?php /* If this is a daily archive */ } elseif (is_day()) { ?>
<p><?php printf(__(‘You are currently browsing the %2$s blog archives for the day %3$s.’, ‘kubrick’), get_bloginfo(‘url’), get_bloginfo(‘name’), get_the_time(__(‘l, F jS, Y’, ‘kubrick’))); ?></p><?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
<p><?php printf(__(‘You are currently browsing the %2$s blog archives for %3$s.’, ‘kubrick’), get_bloginfo(‘url’), get_bloginfo(‘name’), get_the_time(__(‘F, Y’, ‘kubrick’))); ?></p><?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
<p><?php printf(__(‘You are currently browsing the %2$s blog archives for the year %3$s.’, ‘kubrick’), get_bloginfo(‘url’), get_bloginfo(‘name’), get_the_time(‘Y’)); ?></p><?php /* If this is a search result */ } elseif (is_search()) { ?>
<p><?php printf(__(‘You have searched the %2$s blog archives for ‘%3$s’. If you are unable to find anything in these search results, you can try one of these links.’, ‘kubrick’), get_bloginfo(‘url’), get_bloginfo(‘name’), wp_specialchars(get_search_query(), true)); ?></p><?php /* If this set is paginated */ } elseif (isset($_GET[‘paged’]) && !empty($_GET[‘paged’])) { ?>
<p><?php printf(__(‘You are currently browsing the %2$s blog archives.’, ‘kubrick’), get_bloginfo(‘url’), get_bloginfo(‘name’)); ?></p><?php } ?>
if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar() ) : ?><!– Author information is disabled per default. Uncomment and fill in your details if you want to use it.
–>
<?php if ( is_404() || is_category() || is_day() || is_month() ||
is_year() || is_search() || is_paged() ) {
?><?php }?>
<ul role=”navigation”>
<?php wp_list_pages(‘title_li=<h2>’ . __(‘Pages’, ‘kubrick’) . ‘</h2>’ ); ?>- <h2><?php _e(‘Archives’, ‘kubrick’); ?></h2>
-
<?php wp_get_archives(‘type=monthly’); ?>
<?php wp_list_categories(‘show_count=1&title_li=<h2>&order=desc’ . __(‘Categories’, ‘kubrick’) . ‘</h2>’); ?>
-
<?php /* If this is the frontpage */ if ( is_home() || is_page() ) { ?>
- <h2><?php _e(‘Meta’, ‘kubrick’); ?></h2>
<?php wp_list_bookmarks(); ?>-
<?php wp_register(); ?>
- <?php wp_loginout(); ?>
- “><?php _e(‘Valid <abbr title=”eXtensible HyperText Markup Language”>XHTML</abbr>’, ‘kubrick’); ?>
- <abbr title=”<?php _e(‘XHTML Friends Network’, ‘kubrick’); ?>”><?php _e(‘XFN’, ‘kubrick’); ?></abbr>
- “>WordPress
<?php wp_meta(); ?>
<?php } ?>
<?php endif; ?>
</div><!–sidebar–>
<div id=”sidebar2″ role=”complementary”>
-
<?php /* Widgetized sidebar, if you have the plugin installed. */
- <?php get_search_form(); ?>
- <h2><?php _e(‘Author’, ‘kubrick’); ?></h2>
<p>A little something about you, the author. Nothing lengthy, just an overview.</p> -
<?php /* If this is a 404 page */ if (is_404()) { ?>
<?php /* If this is a category archive */ } elseif (is_category()) { ?>
<p><?php printf(__(‘You are currently browsing the archives for the %s category.’, ‘kubrick’), single_cat_title(”, false)); ?></p><?php /* If this is a daily archive */ } elseif (is_day()) { ?>
<p><?php printf(__(‘You are currently browsing the %2$s blog archives for the day %3$s.’, ‘kubrick’), get_bloginfo(‘url’), get_bloginfo(‘name’), get_the_time(__(‘l, F jS, Y’, ‘kubrick’))); ?></p><?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
<p><?php printf(__(‘You are currently browsing the %2$s blog archives for %3$s.’, ‘kubrick’), get_bloginfo(‘url’), get_bloginfo(‘name’), get_the_time(__(‘F, Y’, ‘kubrick’))); ?></p><?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
<p><?php printf(__(‘You are currently browsing the %2$s blog archives for the year %3$s.’, ‘kubrick’), get_bloginfo(‘url’), get_bloginfo(‘name’), get_the_time(‘Y’)); ?></p><?php /* If this is a search result */ } elseif (is_search()) { ?>
<p><?php printf(__(‘You have searched the %2$s blog archives for ‘%3$s’. If you are unable to find anything in these search results, you can try one of these links.’, ‘kubrick’), get_bloginfo(‘url’), get_bloginfo(‘name’), wp_specialchars(get_search_query(), true)); ?></p><?php /* If this set is paginated */ } elseif (isset($_GET[‘paged’]) && !empty($_GET[‘paged’])) { ?>
<p><?php printf(__(‘You are currently browsing the %2$s blog archives.’, ‘kubrick’), get_bloginfo(‘url’), get_bloginfo(‘name’)); ?></p><?php } ?>
if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(2) ) : ?><!– Author information is disabled per default. Uncomment and fill in your details if you want to use it.
–>
<?php if ( is_404() || is_category() || is_day() || is_month() ||
is_year() || is_search() || is_paged() ) {
?><?php }?>
<ul role=”navigation”>
<?php wp_list_pages(‘title_li=<h2>’ . __(‘Pages’, ‘kubrick’) . ‘</h2>’ ); ?>- <h2><?php _e(‘Archives’, ‘kubrick’); ?></h2>
-
<?php wp_get_archives(‘type=monthly’); ?>
<?php wp_list_categories(‘show_count=1&title_li=<h2>&order=desc’ . __(‘Categories’, ‘kubrick’) . ‘</h2>’); ?>
-
<?php /* If this is the frontpage */ if ( is_home() || is_page() ) { ?>
- <h2><?php _e(‘Meta’, ‘kubrick’); ?></h2>
<?php wp_list_bookmarks(); ?>-
<?php wp_register(); ?>
- <?php wp_loginout(); ?>
- “><?php _e(‘Valid <abbr title=”eXtensible HyperText Markup Language”>XHTML</abbr>’, ‘kubrick’); ?>
- <abbr title=”<?php _e(‘XHTML Friends Network’, ‘kubrick’); ?>”><?php _e(‘XFN’, ‘kubrick’); ?></abbr>
- “>WordPress
<?php wp_meta(); ?>
<?php } ?>
<?php endif; ?>
</div><!–sidebar2–>
最後に各 index.php archive.php single.php の <?php get_sidebar(); ?> の下に <?php get_sidebar(2); ?> 追加しました。
これで固定ページもアーカイブページもサイドバーは表示されていたんですが間違っていますか。
宜しくお願いします。コードの書き方が不正確なので以下でチャレンジ。
functions.php:
※sidebar.php の内容はコピーしなくて OK。if ( function_exists('register_sidebar') ) { register_sidebars(2); register_sidebar(array( 1, 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>', )); register_sidebar(array( 2, 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>', )); }
index.php, archive.php, single.php:
<?php get_sidebar(1); get_sidebar(2); ?>
で、single.php だけサイドバーが表示されないなら
single.php の get_sidebar(1); 以前の記述が間違っていると思われます。よくわからない場合は問題の発生している URL を提示いただくと話が早いかもです。
タイトルの背景がアップできませんでしたが、http://eiji.in/wp/こちらの総合をクリックしタイトルをクリックしてみてください。
宜しくお願いします。やっぱり駄目ですね。
そこで新規の default の single.php の <?php get_footer(); ?> の上に <?php get_sidebar(); ?> を追加してみましたが、シングルページはサイドバーがないですね。一歩前進です。
サイドバー1は表示されるようになりました。
原因はシングルページの content に css でセンター配置にしてあった為、カラム落ちしていたのを見逃していたようです。
しかしサイドバー2は表示されません。
それからダッシュボードでウィジェットを見るとサイドバーが1,2,3,4と4っつもありました。
これはどういうことでしょうか。長い事申し訳ありませんがもう少しお付き合いください。宜しくお願いします。シングルページはサイドバーがない
http://eiji.in/wp/ は URL を提示された時からどのページでもどのブラウザで見てもサイドバー1しか表示されていません。
ので、見ているサイトが違う気がします。やっぱり駄目ですね。〜<?php get_sidebar(); ?> を追加
「<?php get_sidebar(); ?> を追加」とは返信していないので、これも何かが違う気がします。
5個前の返信の内容をお試しください。
functions.php:
※sidebar.php の内容はコピーしなくて OK。if ( function_exists('register_sidebar') ) { register_sidebars(2); register_sidebar(array( 1, 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>', )); register_sidebar(array( 2, 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>', )); }
index.php, archive.php, single.php:
<?php get_sidebar(1); get_sidebar(2); ?>
kz さん、教えて頂いた方法ではどうしても上手くいきませんでした。
貴重な時間を割いて、折角教えて頂いたのに生かしきれずに申し訳ありません。
それで代案を検索したところカナログさんのブログで「WordPress2.7のデフォルトテーマを3カラムにする~ソース編~」というのをみて、以下の様にして上手くいきました。
sidebar.phpを以下内容に書き換え
01 <div id=”sidebar”>
02 <ul class=”sidebar1″>
03 <?php if ( !function_exists(‘dynamic_sidebar’)
04
05 || !dynamic_sidebar(‘sidebar1’) ) : ?>
06 <?php endif; ?>
07
08 <ul class=”sidebar2″>
09 <?php if ( !function_exists(‘dynamic_sidebar’)
10
11 || !dynamic_sidebar(‘sidebar2’) ) : ?>
12 <?php endif; ?>
13
14 </div>
functions.phpの部分をを以下内容に書き換え
01 if ( function_exists(‘register_sidebar’) )
02 register_sidebar(array(‘name’=>’sidebar1’,
03 ‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
04 ‘after_widget’ => ”,
05 ‘before_title’ => ‘<h2 class=”widgettitle”>’,
06 ‘after_title’ => ‘</h2>’,
07 ));
08 register_sidebar(array(‘name’=>’sidebar2’,
09 ‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
10 ‘after_widget’ => ”,
11 ‘before_title’ => ‘<h2 class=”widgettitle”>’,
12 ‘after_title’ => ‘</h2>’,
13 )); }
後は css 調整して2列のサイドバーが出来ました。
この度はお世話になり有難うございました。また宜しくお願いいたします。
- トピック「default で検索結果のページにサイドバーを表示させたい」には新たに返信することはできません。