特定のページ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; ?>
関連
おすすめ
- カテゴリーページの時にURLに/categoryがついてしまう時の対処 - 0 views
- テキストリンクの色いろいろ - 0 views
- WordPressのSEO対策に…Google XML Sitemapsプラグイン - 0 views
- リンク切れに有効!Broken Link Checker - 0 views
- よけいなものは要らない!meta情報の編集 - 0 views