【问题标题】:Wordpress Front page and Post Page are displaying the the same contentWordpress Front page 和 Post Page 显示相同的内容
【发布时间】: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.phppage-news.php 而不是 news.php。这些是您需要在活动主题文件夹中使用的名称。语法为page-&lt;slug of the page&gt;
  • 谢谢!我知道这会很简单! :-)

标签: php wordpress-theming wordpress


【解决方案1】:

发布完整的详细信息。

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

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

Pages -&gt; Add New -&gt; Home

Pages -&gt; Add New -&gt; News

您可以为页面输入任何标题,但请确保它们具有标记 homenews

现在,阅读设置。设置 > 阅读:

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

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

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

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

【讨论】:

    【解决方案2】:

    这可能应该移到WordPress area

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

    出于您的目的,听起来您需要将主页模板命名为“front-page.php”,将新闻页面命名为“home.php”

    注意:这仅适用于您正在创建主题。如果您正在修改主题,最好给您的页面模板命名,如下所示:“page-news.php”和“page-home.php”。 See this answer for more details.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-14
      • 2011-04-20
      • 2016-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多