【发布时间】: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