【问题标题】:WordPress: get_header() not including header in template fileWordPress:get_header() 不包括模板文件中的标题
【发布时间】:2016-01-18 22:16:56
【问题描述】:

我使用类型插件创建了称为客户端的自定义帖子类型,并为该类型创建了一个称为客户端的页面。为了从客户端文件中的自定义帖子类型中获取数据,我创建了名为 clients-template.php 的模板,这是其中的代码

<?php
/**
 * Template Name: Client Template
 *
 * @package WordPress
 * @subpackage Twenty_Fourteen
 * @since Twenty Fourteen 1.0
 */
?> 
<?php get_header(); ?>
<div id="main-content" class="main-content"> 
<div id="primary" class="content-area">
    <div id="content" class="site-content" role="main">
        <?php
                            $args=array('post_type' => 'client');
                            $query= new WP_Query($args);                               
            // Start the Loop.
            while ($query-> have_posts() ) : $query->the_post();

                                    echo the_title();
                                    echo the_post_thumbnail();


            endwhile;
        ?>
    </div><!-- #content -->
</div><!-- #primary -->

现在,当我使用此模板添加页面时,我希望它显示标题,然后显示此特定帖子类型的内容,但它不添加标题有什么问题请帮助我

【问题讨论】:

  • 主题是否包含header.php 文件?尝试使用include 函数包含它。
  • 是的,模板在 page-templates 文件夹中,页眉在主文件夹中
  • 然后include ('../header.php');
  • 不要将标题包含在包含中 - 这不是 WordPress 的工作方式。 get_header() 应该可以在主题的根目录中引入 header.php 模板。如果它不工作,那么你应该启用调试定义('WP_DEBUG',true);在您的 wp-settings.php 中查看是否出现任何错误。

标签: php wordpress custom-post-type


【解决方案1】:
<?php
/**
 * Template Name: Client Template
 *
 * @package WordPress
 * @subpackage Twenty_Fourteen
 * @since Twenty Fourteen 1.0
 */
    get_header(); 
?>
<div id="main-content" class="main-content"> 
<div id="primary" class="content-area">
    <div id="content" class="site-content" role="main">
        <?php
                            $args=array('post_type' => 'client');
                            $query= new WP_Query($args);                               
            // Start the Loop.
            while ($query-> have_posts() ) : $query->the_post();

                                    echo the_title();
                                    echo the_post_thumbnail();


            endwhile;
        ?>
    </div><!-- #content -->
</div><!-- #primary -->
</div><!-- #main-content -->

<?php
get_footer();
?>

【讨论】:

  • 你能解释一下吗,有什么不同?对原海报会更有帮助。
  • 请调用页脚以便删除 javascript 错误。因为有时 javascript 错误所以没有正确播种标题。
猜你喜欢
  • 1970-01-01
  • 2018-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多