【发布时间】:2014-05-05 21:57:57
【问题描述】:
我正在开发一个基本的 Wordpress 网站,并希望主页是一个自定义静态页面,所以我创建了一个名为 home.php 的页面和一个名为 news.php 的页面,然后在 WP 管理员中我走了收件人:Setting 然后Reading 选择a static page 选项,选择Front Page 作为主页,然后选择Posts Page 作为新闻。
但是,当我在浏览器中查看该站点时,两个页面显示相同的内容..尽管 URL 确实更改为页面的内容,即: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>
如果有人可以帮助我找出我哪里出错了,将不胜感激! :-)
【问题讨论】:
-
以index.php为首页,single.php为post页。
-
page-home.php而不是home.php和page-news.php而不是news.php。这些是您需要在活动主题文件夹中使用的名称。语法为page-<slug of the page> -
谢谢!我知道这会很简单! :-)
标签: php wordpress-theming wordpress