我正在制作一个wordpress,其中包括用于显示新闻的Front Page和Post Page。
根据我的理解,Post Page使用的模板是index.php,但index.php也被其他页面使用。
问题是我想为帖子创建一个特殊页面,其中有一个标题说明新闻等,但我不希望其他页面使用该模板。 有没有办法创建一个仅用于显示帖子的替代index.php(index_news.php)?
这样我可以使用index_news.php作为post,将index.php用于其他所有内容。
谢谢
编辑//////////我的第一个选择是创建一个带有循环内部的新页面模板(news.php),然后在wordpress选项中将帖子定位到该新页面(news.php)。
但是当我这样做时,它会加载index.php而不是news.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. -->
答案 0 :(得分:0)
single.php - 用于一个帖子视图,但如果您想修改博客索引,那么您还可以创建一个自定义模板(page-news.php),其标题允许将其分隔为页面模板:
<?php
/*
* Template Name: News Page
* @package WordPress
*/
?>
然后在其中使用循环。 但是对于这种情况我认为更好,你可以修改header.php并使用wordpress条件标签,例如: is_front_page(),is_page()或任何适用于您的内容:http://codex.wordpress.org/Conditional_Tags
有很多方法可以做同样的事情;)。