dongzhan5246 2016-11-14 21:33
浏览 41

Home.php无效

I have an issue with home.php on a WordPress theme I'm developing.

I'm trying to make a page that displays the latest posts. I've ascertained that this is called 'home.php.'

I'm following a tutorial that includes a template for home.php. The problem is, the home.php isn't being read. Instead, it seems that the browser is showing index.php in place of home.php. I know it's not posting anything from home.php because because if I delete all the code from the home.php and save it as a blank document, it has zero effect on what the browser displays.

Here's the PHP/HTML I'm using:

<?php get_header(); ?>

<div class="row">
  <div class="span8">

  <h1>News</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>
<hr>

<?php endwhile; else: ?>
 <p><?php _e('Sorry, there are no posts.'); ?></p>
<?php endif; ?>

</div>

<div class="span4">
<?php get_sidebar(); ?> 
</div>

</div>

<?php get_footer(); ?>
  • 写回答

1条回答 默认 最新

  • dtcwehta624485 2016-11-14 21:42
    关注

    Change your opening line <?php get_header(); ?> to the following

    <?php
        /* Template Name: Homepage */
        get_header();
    ?>
    

    Then go and create a page inside of the WordPress admin area and assign that page to use the template named "Homepage" by changing the dropdown in this screenshot: http://smb-infogroup-dpr.d.pr/Jw4P/2cXQVFLL

    Then you'll need to go to Settings > Reading and set the two options in this screenshot: http://smb-infogroup-dpr.d.pr/Svk0/58SLZIEq. The second option will be the name of the page you created and assigned the template to.

    index.php is the default template file used unless you assign a static page to the homepage.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分