我正在一个基本的Wordpress网站上工作,并希望主页是一个自定义的静态页面,所以我创建了一个名为home.php
的页面和一个名为news.php
的页面,然后在WP管理中我去了:Setting
然后Reading
选择了a static page
选项,选择了Front Page
作为主页,然后选择了Posts Page
作为新闻。
然而,当我在浏览器中查看网站时,两个页面显示相同的内容。尽管URL不会改变为任何页面是ie: localhost:8888/mysite/home or localhost:8888/mysite/news
我不确定我是否错过了一些非常简单的…但我似乎不知道我错在哪里?
我的主页代码是:
<?php
/*
Template Name: Home Page
*/
?>
<?php get_header(); ?>
<div class="container">
<h1>This is the homepage</h1>
</div>
<?php get_footer(); ?>
新闻页面的代码是:
<?php
/*
Template Name: News Page
*/
?>
<?php get_header(); ?>
<div class="container">
<h2>This is the Blog page</h2>
<?php $args = array(
'post_type' => 'post',
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => 4,
'paged' => get_query_var('paged'),
'post_parent' => $parent
); ?>
<?php query_posts($args); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<article>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
<time><?php the_time(get_option('date_format')); ?></time>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</article>
<?php endwhile; ?>
<?php endif; ?>
<?php get_footer(); ?>
</div>
如果有人能帮我弄清楚我错在哪里,那将是非常感激的!: -)
张贴详情
首先,确保您的.php
文件在活动主题文件夹内。(例如:/wp-content/themes/<themename>/
)。
先在wordpress内创建2个静态页面:
Pages -> Add New -> Home
Pages -> Add New -> News
你可以为页面输入任何标题,但要确保它们有home
和news
。
现在,读取设置。设置>阅读:
首页显示:(x)静态页面
Front Page: <choose **home** which you created earlier>
Posts Page: <choose **news** which you created earlier>
现在,对于自定义主页,将php文件命名为page-home.php
,将新闻文件命名为page-news.php
。
这个应该移到WordPress区域。
你的主题中文件名是什么?WordPress使用层次结构来确定在构建页面时使用哪个模板。你可以在手抄本里读到更多。
对于你的目的,这听起来像是你需要命名你的主页模板'front-page.php'和你的新闻页面'home.php'
注意:这仅在创建主题时使用。如果你正在修改一个主题,最好给你的页面模板命名为:'page-news.php'和'page-home.php'。