简体   繁体   English

WordPress帖子页面PREVIEW使用index.php而不是home.php

[英]WordPress posts page PREVIEW using index.php instead of home.php

So I'm kind of lost here. 所以我有点迷路了。 I have set a static front page, decalring my Home page as the front page, which uses index.php, and I have declared my static posts page as my News & Events page. 我设置了一个静态首页,将我的主页缩放为使用index.php的首页,并且将静态帖子页面声明为“新闻与事件”页面。

Now, whenever I make changes and try to preview my News & Events page, it is using my index.php template instead of my home.php (which I am under the impression is the default template for the static post page). 现在,每当我进行更改并尝试预览“新闻与事件”页面时,它都使用index.php模板而不是home.php(我印象中的模板是静态帖子页面的默认模板)。

The weird thing is, whenever I navigate to the News & Events page via the actual website and not the preview, everything is showing up correctly and using the correct home.php template. 奇怪的是,每当我通过实际网站而不是预览导航到“新闻与事件”页面时,一切都正确显示并使用正确的home.php模板。 So, in essence, everything is working the way I would want it to, but the fact that the preview brings me to index.php/my homepage (even though the URL shows I am supposed to be previewing the right page ID), has me concerned. 因此,从本质上讲,一切都按照我想要的方式工作,但是预览将我带到index.php /我的主页(即使该URL显示我应该预览正确的页面ID)这一事实也具有我担心。

HERE is my index.php 这里是我的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(); ?>

HERE is my home.php 这里是我的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(); ?>

Thanks in advance for any help! 在此先感谢您的帮助!

This is not how the Template Hierarchy works. 这不是模板层次结构的工作方式。 Yes, your blogpage uses home.php and if it is not found, defaults to index.php. 是的,您的博客页面使用home.php,如果未找到,则默认为index.php。 Your assumption about your front page is wrong though. 但是您对首页的假设是错误的。

The front page uses front-page.php, if not found, a custom template or any page.php type template. 如果未找到,首页使用front-page.php,自定义模板或任何page.php类型模板。 Check out Creating a static front page 签出创建静态首页

As far the problem with your blogpage, it should be using home.php by default. 至于您的博客页面的问题,默认情况下应该使用home.php。 I think why it is using index.php is due to some caching plugin or browser cache. 我认为为什么使用index.php是由于某些缓存插件或浏览器缓存。 Clear these caches and check if your problem still exists 清除这些缓存并检查问题是否仍然存在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM