WordPressで複数サイドバー対応

複数サイドバー設定を試して見ました。

結構、ハマリ事が多いですネ~
スンナリと思う様に動いてくれません。

ネットで調べるとイロイロと検索に引っかかって来るの
ですが・・・

特にウィジェットの辺りは悩みどころです。

結局のところ、実地で試すしかありませんネ。

何とか形は出来上がりました。
出来てしまえば、どうと言う事もないのですが、やはり人様が
組み上げたテンプレートに手を入れるのは大変です。

結果的にカスタマイズでは無くスタイルシートは新規作成し
PHPコードは、元のテーマの原型がありません・・・

以下が設定メモです。 次に備えてメモっときます。

1.sidebar.phpの編集
 (1) テーマに付随するsidebar.phpは放棄
 (2) defaultテーマからsidebar.phpを移植
 (3) 上記、sidebar.phpをコピーしsidebar-2.phpを作成
 (4) 上記、2つのsidebar.phpをFTPでサーバへアップ
 (5) 2つのsidebar.phpをウィジェット対応にする
    ↓ ↓ ↓ defaultの状態
 <div id=”sidebar” role=”complementary”>
         <ul>
         <?php  /* Widgetized sidebar, if you have the plugin installed. */
            if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar() ) : ?>
       <li>

         dynamic_sidebar()   → dynamic_sidebar(1)      ← sidebar.phpの場合
    sidebar-2.phpはdynamic_sidebar(1) を (2) に変更

今回は、sidebar.phpを左バー用にsidebar-2.phpを右バー用に設定

2.functions.phpの編集 以下の変更で完了

  if ( function_exists(‘register_sidebar’) )
       register_sidebar();
    ↓  ↓  ↓  ↓
  if ( function_exists(‘register_sidebars’) )
        register_sidebars(‘2′);

2つの regster_sidebar を regster_sidebars に変更。
2つ目のregster_sidebarの()内の数値はサイドバーの数。

3.index.php、page.php、search.php、single.phpを
  複数サイドバーが表示される様に変更

  以下はモジュールコーディング例(index.php)

     <?php get_header(); ?>
         <div id=”wrapper”>
               <div id=”cont-body”>
                     <?php if(have_posts()) : ?>
                          <?php while(have_posts()) : the_post(); ?>
             以下、中略
                ・
                ・
                         <?php endwhile; ?>
                    <?php endif; ?>
               </div>
         </div>
     <?php get_sidebar(); ?>
     <?php get_footer(); ?>

     <?php get_header(); ?>
         <div id=”wrapper”>
               <div id=”cont-body”>
                     <?php if(have_posts()) : ?>
                          <?php while(have_posts()) : the_post(); ?>
             以下、中略
                ・
                ・
                         <?php endwhile; ?>
                    <?php endif; ?>
               </div>
               <?php get_sidebar(1); ?> ← set_sidebarの追加
         </div>
     <?php get_sidebar(2); ?> ←モジュールの()内の数値が重要
     <?php get_footer(); ?>

後は、スタイルシートを3カラム対応して完了。
各phpモジュールをスタイルシートへ合わせ込み。

 

コメントをどうぞ

XHTML: 以下のタグが使用できます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

spacer tag