dpwo36915 2014-05-05 12:48
浏览 22
已采纳

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

I am working on a basic Wordpress website and wanted the home page to be a custom static page, so I have created a page called home.php and and page called news.php and then in the WP admin I've gone to: Setting then Reading selected the a static page option, selected the Front Page as Home and then the Posts Page as News.

However when Ive gone to view the site in the browser both pages display the same content.. allthough the URL DOES change to what ever the page is ie: localhost:8888/mysite/home or localhost:8888/mysite/news

I'm not sure if i'm missing something really simple.. but I can't seem to figure out where I am going wrong?

My Code for the home page is:

<?php 
/*
Template Name: Home Page
*/
?>

<?php get_header(); ?>

<div class="container">

<h1>This is the homepage</h1>

</div>    

<?php get_footer(); ?>

and then my code for the News page is:

<?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>

If anyone could help me try to figure out where I am going wrong, it would be greatly appreciated! :-)

  • 写回答

2条回答 默认 最新

  • dongshang4984 2014-05-05 12:59
    关注

    This should probably be moved to the WordPress area.

    What are your files named in your theme? WordPress uses a hierarchy to determine which template to use when building a page. You can read more about that in the codex.

    For your purposes, it sounds like you need to name your home page template 'front-page.php' and your news page 'home.php'

    Note: This is only if you're creating a theme. If you're modifying a theme, its better to give your page templates names like so: 'page-news.php' and 'page-home.php'. See this answer for more details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭