フォーラム

シングルページを複数作りたい場合 (3 件の投稿)

  1. bjifa
    メンバー
    4 ヶ月前の投稿 #

    現在下記のように、記事のタイトルをシングルページにリンクしているのですが、
    シングルページを複数作りたい、
    巧く表現できないのですが、single.php ではない特定のページ(テンプレートを指定してある)でその記事を表示させたいのですが、どのようにすればよろしいのでしょうか?

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php endwhile; endif; ?>
  2. bjifa
    メンバー
    4 ヶ月前の投稿 #

    自己レスです。

    <?php if(is_single()&&in_category('1'))
    { include (TEMPLATEPATH . '/efgh.php'); return; }
    ?>

    を single.php の<head>の前に記述することでできました。

    http://www.adphic.jp/wp/templatetag-tips/tips-include/

    こちらを参考にしました。

    もっといいやり方があれば、教えてください。

  3. Nao
    管理者
    4 ヶ月前の投稿 #

    http://www.nathanrice.net/blog/wordpress-single-post-templates/

    single-1.php, single-2.php というようなテンプレート(数字はカテゴリー ID と一致させる)を作り、テンプレートフォルダ内の functions.php ファイルに以下を書き込むという例が紹介されています。

    <?php add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ) return TEMPLATEPATH . "/single-{$cat->term_id}.php"; } return $t;' ));
    ?>

返信

ログイン しなければ投稿できません。

About this Topic

Tags

タグ はまだありません。