我有我的首页设置为静态页面,我试图建立我的自定义模板。如何在front-page。php中显示选中的首页?我在谷歌上搜索了又搜索,但似乎不知道该怎么做。
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. ?>
您的静态页面使用一个页面模板(通常为默认模板page.php)
如果你愿意,你可以为主页创建一个新的。参见:Creating_Your_Own_Page_Templates将page.php
复制到homepage.php
并更改模板名称
模板示例(home .php):
<?php
/*
Template Name: Homepage
*/
//the content of page.php and now you can do what you want.
?>
$id = 0; /* The id of your page */
$page = get_page($id);
echo apply_filters('the_content', $page->post_content);
如果是静态页面,我不应该使用循环
首先,查看主题,以便仅在主页上显示某些内容。一个相关的问题是Wordpress帖子缩略图问题(首页只有一个缩略图)。此外,如何在wordpress中创建静态首页也很有用。
我错过了一些明显的东西。我使用的循环是从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;?>