![](/img/trans.png)
[英]Wordpress is not using home.php and instead index.php for posts page.
[英]WordPress posts page PREVIEW using index.php instead of home.php
所以我有点迷路了。 我设置了一个静态首页,将我的主页缩放为使用index.php的首页,并且将静态帖子页面声明为“新闻与事件”页面。
现在,每当我进行更改并尝试预览“新闻与事件”页面时,它都使用index.php模板而不是home.php(我印象中的模板是静态帖子页面的默认模板)。
奇怪的是,每当我通过实际网站而不是预览导航到“新闻与事件”页面时,一切都正确显示并使用正确的home.php模板。 因此,从本质上讲,一切都按照我想要的方式工作,但是预览将我带到index.php /我的主页(即使该URL显示我应该预览正确的页面ID)这一事实也具有我担心。
这里是我的index.php
<?php get_header(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, this page does not exist.'); ?></p>
<?php endif; ?>
<?php get_footer(); ?>
这里是我的home.php
<?php get_header(); ?>
<section id="news">
<div class="row">
<div class="container">
<div class="col-md-8">
<h1 style="margin-bottom:50px">News and Events</h1>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><em><?php the_time('l, F jS, Y'); ?></em></p>
<p>Category: <?php the_category(', ') ?></p>
<p><?php the_tags(); ?> </p>
<hr>
<?php the_excerpt(); ?>
<?php comments_template() ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, there are no posts.'); ?></p>
<?php endif; ?>
</div>
<div class="col-md-4" style="margin-bottom:50px">
<?php get_sidebar(); ?>
</div>
</div>
</div>
</section>
<?php get_footer(); ?>
在此先感谢您的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.