0

私は、とりわけニュースを表示するためのフロントページとポストページを備えたワードプレスに取り組んでいます。

私が理解しているところによると、投稿ページが使用するテンプレートは index.php ですが、index.php は他のページでも使用されています。

問題は、投稿用の特別なページを作成し、ニュースなどのヘッダーを付けたいのですが、他のページでそのテンプレートを使用したくないということです。投稿を表示するためだけに使用される代わりの index.php (index_news.php) を作成する方法はありますか?

そうすれば、投稿に index_news.php を使用し、他のすべてに index.php を使用できます。

ありがとう

編集 //////////

私の最初のオプションは、内部にループを含む新しいページ テンプレート (news.php) を作成することでした。次に、wordpress オプションで、その新しいページ (news.php) への投稿をターゲットにしました。

しかし、これを行うと、news.php テンプレートではなく index.php が読み込まれます。たぶん、ループに何か問題があります。私が使用しているループは次のとおりです。

<!-- Start the Loop. -->
<div class="post">
    <!-- Display the Title as a link to the Post's permalink. -->
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

     <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
     <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>

     <!-- Display the Post's content in a div box. -->
     <div class="entry">
       <?php the_content(); ?>
     </div>

     <!-- Display a comma separated list of the Post's Categories. -->
     <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
</div> <!-- closes the first div box -->

 <!-- Stop The Loop (but note the "else:" - see next line). -->
 <?php endwhile; else: ?>

 <!-- The very first "if" tested to see if there were any Posts to -->
 <!-- display.  This "else" part tells what do if there weren't any. -->
 <p>Sorry, no posts matched your criteria.</p>

 <!-- REALLY stop The Loop. -->
4

1 に答える 1

0

single.php - 1 つの投稿ビュー用ですが、ブログ インデックスを変更したい場合は、ページ テンプレートとして分離できるヘッダーを持つカスタム テンプレート (page-news.php) を作成することもできます。

<?php
/*
 * Template Name: News Page
 * @package WordPress
 */
?>

その中でループを使用します。しかし、この場合はさらに良いと思います。header.php を変更して、is_front_page()、is_page() などの wordpress 条件付きタグを使用するか、またはあなたのために機能するものを使用できます: http://codex.wordpress.org/条件付き_タグ

同じことをする方法はたくさんあります;)。

于 2013-02-08T14:40:33.960 に答える