Wordpress首页和帖子页面显示相同的内容

时间:2014-05-05 12:48:01

标签: php wordpress-theming wordpress

我正在使用一个基本的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>

如果有人能帮助我找出错误的地方,我们将不胜感激! : - )

2 个答案:

答案 0 :(得分:1)

发布完整详情。

首先,确保您的.php文件位于活动主题文件夹中。 (例如:/wp-content/themes/<themename>/)。

首先在wordpress中创建2个静态页面:

Pages -> Add New -> Home

Pages -> Add New -> News

您可以为该页面输入任何标题,但要确保它们有slu homenews

现在,阅读设置。设置&gt;读:

首页显示:(x)静态页面

 Front Page: <choose **home** which you created earlier>

 Posts Page: <choose **news** which you created earlier>

现在,对于自定义主页,请为您的php文件page-home.php和新闻page-news.php命名。将它们放在活动主题文件夹中。

答案 1 :(得分:0)

这可能应该移到WordPress area

您的主题中指定了哪些文件? WordPress使用层次结构来确定构建页面时要使用的模板。你可以read more about that in the codex.

出于您的目的,您可能需要为主页模板命名&#39; front-page.php&#39;和你的新闻页面&#39; home.php&#39;

注意:仅在您创建主题时才会这样做。如果您要修改主题,最好为您的网页模板命名,例如:&#39; page-news.php&#39;和&#39; page-home.php&#39;。 See this answer for more details.

相关问题