Wordpress front-page.php模板

时间:2013-03-15 17:27:48

标签: php wordpress

我将首页设置为静态页面,并尝试构建自定义模板。如何在front-page.php中实际显示所选的首页?我用google搜索和Google搜索,但似乎无法弄明白该怎么做。

front-page.php实际上是按照它应该加载的,但我似乎无法找到关于如何显示分配为静态主页的页面的文档。有什么建议吗?

我试过了

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

但这似乎不起作用......

4 个答案:

答案 0 :(得分:0)

$id = 0; /* The id of your page */
$page = get_page($id);
echo apply_filters('the_content', $page->post_content);

如果是静态页面,我不应该使用循环。

答案 1 :(得分:0)

答案 2 :(得分:0)

您的静态页面使用页面模板(通常是page.php作为默认模板)

如果您愿意,可以为主页创建一个新的。请参阅:Creating_Your_Own_Page_Templatespage.php复制到homepage.php并更改模板名称

示例模板(homepage.php):

<?php
/*
Template Name: Homepage
*/

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

答案 3 :(得分: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;?>
相关问题