2013-03-15 101 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. 
?>