特定のページXに特定のページYを表示させたい

2010.10.29

困ったのでメモ。
query_postsを使ったやり方。

以下。

ページXならば、ページYをとってきて表示する。それ以外のページならなにも表示しない。

<?php if (is_page('ページ名X')): ?>
<?php query_posts('pagename=ページ名Y'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class('クラス名'); ?> id="post-<?php the_ID(); ?>">
<h2 class="title"><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query();?>
<?php endif; ?>

ページX 又は、ページAならば、ページYをとってきて表示する。それ以外のページならなにも表示しない。

<?php if (is_page('ページ名X')||is_page('ページ名A')): ?>
<?php query_posts('pagename=ページ名Y'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class('クラス名'); ?> id="post-<?php the_ID(); ?>">
<h2 class="title"><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query();?>
<?php endif; ?>

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img localsrc="" alt="">