get_sidebar について教えてください。
-
WordPress 3.0 日本語版で自作テーマを作りました。
今のところindex.php,style.css,functions.php の3ファイルですが、index.php のサイドバーの部分をsidebar_right.php という名前で作成して、自作テーマの構成は以下のとおりなので、
<div id="container"> <div id="header"></div> <div id="contents"> <div id="content"></div> <div id="side"></div> </div> <div id="footer"></div> </div>
side で、<?php get_sidebar(‘sidebar_right’); ?> としています。
しかし、sidebar_right.php に書いたコードの「選択した記事と同じカテゴリの投稿一覧」や「最新の記事」、「flickrの画像」を表示する部分が表示されません。
以下がsidebar_right.phpの内容
<!-- start sidebar_right --> <?php if (is_category() || is_single()) : ?> <div id="sidebar"> <ul> <div id="myWidget" class="widget"> <?php $cat = get_the_category(); $cat = $cat[0]; echo '<h4><a href="#">' . $cat->cat_name . '</a></h4>'; $cat = $cat->cat_ID; $category_posts = get_posts("order=desc&category=$cat&numberposts=-1"); ?> <ul> <?php foreach($category_posts as $post): ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> </div> </ul> </div> <?php endif; ?> <div id="sidebar"> <ul> <div id="myWidget" class="widget"> <h4><a href="#">最新の投稿</a></h4> <?php $new_posts = get_posts("order=desc&orderby=date&numberposts=10"); ?> <ul> <?php foreach($new_posts as $post): ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> </div> </ul> </div> <div style="clear:right;"></div> <div id="sidebar"> <ul> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar_right') ) : ?> <?php endif; // endif widget ?> </ul> </div> <div style="clear:right;"></div> <div id="sidebar"> <ul> <div id="myWidget" class="widget"> <h4><a href="#">空の写真(Flickr)</a></h4> <div id="flickr" class="clearfix"> <?php echo gluedideas_FlickrFeeder::displayFeed(); ?> </div> </div> </ul> </div> <!-- end sidebar_right -->
以下がfunctions.phpの関連部分の内容
<?php // Widget Settings if ( function_exists('register_sidebar') ) { register_sidebar(array( 'name' => 'sidebar_right', 'before_widget' => '<div id="%1$s" class="widget">', 'after_widget' => '</div>', 'before_title' => '<h4><a href="#">', 'after_title' => '</a></h4>', )); register_sidebar(array( 'name' => 'sidebar_bottom_left', 'before_widget' => '<div id="%1$s" class="widget">', 'after_widget' => '</div>', 'before_title' => '<h4><a href="#">', 'after_title' => '</a></h4>', )); register_sidebar(array( 'name' => 'sidebar_bottom_middle', 'before_widget' => '<div id="%1$s" class="widget">', 'after_widget' => '</div>', 'before_title' => '<h4><a href="#">', 'after_title' => '</a></h4>', )); register_sidebar(array( 'name' => 'sidebar_bottom_right', 'before_widget' => '<div id="%1$s" class="widget">', 'after_widget' => '</div>', 'before_title' => '<h4><a href="#">', 'after_title' => '</a></h4>', )); } ?>
どなたか問題点を教えて頂けないでしょうか。
宜しくお願い致します。
-
しかし、sidebar_right.php に書いたコードの「選択した記事と同じカテゴリの投稿一覧」や「最新の記事」、「flickrの画像」を表示する部分が表示されません。
とありますが、逆に言うと何か読み込まれているものがあるのでしょうか?
といいますのも、get_sidebar()で指定なされているパラメータsidebar_rightではsidebar_right.phpを読み込めないはずです。
WordPress 2.5 以上では、パラメータとして、サイドバーテンプレートのファイル名(sidebar-この部分.php)を指定できます。テンプレートに TEMPLATEPATH . ‘sidebar-2.php’ を読み込ませるには、次のように書きます。
<?php get_sidebar('2'); ?>
パラメータではファイル名そのものでなく、ファイル名の中の「この部分」を指定するようになっています。
- トピック「get_sidebar について教えてください。」には新たに返信することはできません。