サポート » 使い方全般 » sidebar.php1ファイルで固定ページごとに内容を変えたい

  • 以下の様に一つのカスタム投稿ページ(固定ページ)ごとに、サイドバーの内容を変えようとしています。

    Aのカスタム投稿の一覧ページ・記事単独ページ・アーカイブへは、サイドバーAを表示
    Bのカスタム投稿の一覧ページ・記事単独ページ・アーカイブへは、サイドバーBを表示
    Cのカスタム投稿の一覧ページ・記事単独ページ・アーカイブへは、サイドバーCを表示

    方法としては、sidebar.phpを複数準備して個別で呼び出す方法もあるようですが、
    出来れば極力管理面で解り易すくシンプルにしておきたく思い、
    sidebar.phpの1ファイルに条件分岐でサイドバーの内容を表示出来ればと考えています。

    色々調べ、例えば以下の様な記述を試したのですが表示されませんでした。
    このような場合sidebar.phpにはどの様な記述する方法がありますでしょうか?

    宜しくお願い致します。

    <?php if(is_page(固定ページ名A)): ?>
    <p class="h_lNavi02"><?php echo $post_cat->name; ?>固定ページ名A</p>
    <?php
    $categories = get_categories();
    foreach($categories as $category) :
    ?>
    <ul class="menu">
      <?php
    query_posts('showposts=5&cat='.$category->cat_ID);
    if (have_posts()) : while (have_posts()) : the_post();
    ?>
      <li><a href="<?php the_permalink() ?>">
        <?php the_time('Y-m-d'); ?><br /><?php the_title(); ?>
        </a></li>
      <?php endwhile; endif; ?>
    </ul>
    <?php endforeach; ?>
    <p class="h_lNavi02"><?php echo $post_cat->name; ?>月別一覧</p>
    <ul class="menu">
      <?php wp_get_archives('type=monthly&post_type=book'); ?>
    </ul>
    <?php endif; ?>
    
    <?php if(is_page(固定ページ名B)): ?>
    <p class="h_lNavi02"><?php echo $post_cat->name; ?>固定ページ名B</p>
    <?php
    $categories = get_categories();
    foreach($categories as $category) :
    ?>
    <ul class="menu">
      <?php
    query_posts('showposts=5&cat='.$category->cat_ID);
    if (have_posts()) : while (have_posts()) : the_post();
    ?>
      <li><a href="<?php the_permalink() ?>">
        <?php the_time('Y-m-d'); ?><br /><?php the_title(); ?>
        </a></li>
      <?php endwhile; endif; ?>
    </ul>
    <?php endforeach; ?>
    <p class="h_lNavi02"><?php echo $post_cat->name; ?>月別一覧</p>
    <ul class="menu">
      <?php wp_get_archives('type=monthly&post_type=book'); ?>
    </ul>
    <?php endif; ?>

    参考サイト
    http://tarimon.co.uk/entry/297
    http://wpdocs.sourceforge.jp/条件分岐タグsidebar.php

1件の返信を表示中 - 1 - 1件目 (全1件中)
1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「sidebar.php1ファイルで固定ページごとに内容を変えたい」には新たに返信することはできません。