2013-03-15 59 views
1

我有我的首頁設置爲靜態頁面,並試圖建立我的自定義模板。我如何真正顯示front-page.php中選定的首頁?我已經Google和谷歌搜索,但似乎無法弄清楚如何做到這一點。WordPress的frontpage.php模板

前page.php文件實際上載入像它應該,但我似乎無法找到究竟是如何顯示被指定爲靜態主頁的頁面文件。有什麼建議麼?

我已經試過

<?php while (have_posts()) : the_post(); ?> 
    <?php get_template_part('content', 'page'); ?> 
    <?php comments_template('', true); ?> 
<?php endwhile; // end of the loop. ?> 

,但似乎並沒有工作...

+1

如果您設置一個頁面是在設置首頁 - >讀那麼WordPress會自動應用模板前page.php文件沒有它有在模板菜單中選擇。標準的Loop將使用該特定的文章,而不需要任何自定義查詢。 – McNab 2013-03-15 17:47:59

+0

你是對的。我正在循環並調用模板content-page.php,它實際上具有該帖子的信息。 – user1453561 2013-03-15 17:50:10

回答

0

我失去了一些東西明顯。我使用的循環已經複製出WordPress模板。它實際上稱爲另一個模板文件。我應該使用是:

<?php while (have_posts()) : the_post(); ?> 
      <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
       <header class="entry-header"> 
        <h1 class="entry-title"><?php the_title(); ?></h1> 
       </header> 

       <div class="entry-content"> 
        <?php the_content(); ?> 
        <?php wp_link_pages(array('before' => '<div class="page-links">' . __('Pages:', 'twentytwelve'), 'after' => '</div>')); ?> 
       </div><!-- .entry-content --> 
       <footer class="entry-meta"> 
        <?php edit_post_link(__('Edit', 'twentytwelve'), '<span class="edit-link">', '</span>'); ?> 
       </footer><!-- .entry-meta --> 
      </article><!-- #post --> 
<?php endwhile;?> 
0
$id = 0; /* The id of your page */ 
$page = get_page($id); 
echo apply_filters('the_content', $page->post_content); 

如果它是一個靜態頁面,我不應該使用一個循環。

0

靜態頁面使用頁面模板(通常爲page.php文件的默認模板)

您可以創建網頁一個新的,如果你的願望。見:Creating_Your_Own_Page_Templates複製page.phphomepage.php和更改模板名稱

示例模板(homepage.php):

<?php 
/* 
Template Name: Homepage 
*/ 

//the content of page.php and now you can do what you want. 
?>