2013-02-08 20 views
0

我正在開發一個wordpress,其中包含一個用於顯示新聞的主頁和帖子頁面。在wordpress中創建一個不同的index.php

據我所知,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

你可能想看看這個[Wordpress模板層次概述](http://codex.wordpress.org/Template_Hierarchy)。 – 2013-02-08 14:40:16

回答

0

的single.php - 是一個職位的看法,但如果你wolud要修改博客索引,比你還可以創建自定義模板(頁news.php)具有報頭,其允許它被作爲頁面模板分離:

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

,然後使用循環的它的內部。 但這種情況下我認爲是更好的,你可以修改header.php文件,使用WordPress條件標籤,如: is_front_page(),is_page()或任何會爲你工作:http://codex.wordpress.org/Conditional_Tags

有許多做同樣的方法;)。

+0

嗨Marcin,謝謝你的回覆。 這是我的第一選擇,但沒有任何運氣。我編輯我的問題,包括該信息 – gprego 2013-02-08 15:33:19

+0

好吧,我想通了。 我需要與WP_Query()一起使用循環才能正常工作。 由於我認爲無用,因此我會在幾分鐘內刪除我的問題。 謝謝 – gprego 2013-02-08 15:56:23

+0

或者你可以給一個「加號」並且正確的給出一個很好的答案。 – 2013-02-08 19:32:14

相關問題