【问题标题】:WordPress formatting issues with front-page.phpfront-page.php 的 WordPress 格式问题
【发布时间】:2016-10-10 13:55:14
【问题描述】:

按照本教程: http://blog.teamtreehouse.com/responsive-wordpress-bootstrap-theme-tutorial

教程指导我创建一个 index.php 的内容:

<?php get_header(); ?>

<!-- loop-->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h1><?php the_title(); ?></h1>  
    <?php the_content(); ?>
<?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

<?php get_footer(); ?>

这将创建一个模板,顶部是我的页眉,底部是页脚。然后,教程指示我创建一个包含以下内容的 front-page.php:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php the_content(); ?>
<?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

基本上,与 index.php 相同的内容减去几行代码,最重要的是 &lt;?php get_header(); ?&gt;&lt;?php get_footer(); ?&gt; 命令。问题是,当我创建这个页面时,我的首页不再有页眉或页脚,或者页眉和页脚中的格式。

然而,在教程中,页眉、页脚和格式仍然适用于首页。我做错了什么?

【问题讨论】:

  • 我认为教程的​​人忘记了这行。只需将get_header();get_footer(); 保留在您的front-page.php 中即可。

标签: php wordpress


【解决方案1】:

你没有做错任何事。开发者可能忘了提及添加它,仅此而已。

当您使用front-page.php 时,WordPress 在呈现首页时不会使用index.php,除非您将get_header()get_footer() 添加到front-page.php,否则无法包含页眉和页脚。

添加页眉和页脚,您应该会在教程中看到您的首页作为屏幕截图,并通知开发人员在他的教程中修复此问题

【讨论】:

  • 谢谢艾哈迈德!很奇怪,因为编写教程的人明确提到删除 front-page.php 的 get_header()get_footer() 命令
  • 我找不到说明删除页眉和页脚的部分。我只找到remove the get_title()。他只是忘了把它添加到代码中
  • 你是对的。它说只是删除get_title()--我猜这是它说“你的代码应该看起来像这样”的部分——同时排除了两个重要的标签。
【解决方案2】:

嗨,马特创建一个页面主页模板并在其中调用页眉和页脚,然后您将调用发布它的工作。

【讨论】:

    【解决方案3】:

    您也可以创建自定义页眉和页脚。

    创建您的自定义标题,例如“header-custom.php”

    要包含此标头,您需要 &lt;?php get_header('custom'); ?&gt; 之后 - 是您的自定义标头的名称,当您调用标头时,您需要像我上面所做的那样在函数中插入名称。

    对于页脚也相同的登录和侧边栏也相同的逻辑。

    页脚-custom.php、侧边栏-custom.php

    <?php
    get_footer('custom');
    ?>
    
    <?php 
    get_sidebar('custom');
    ?>
    

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多