【发布时间】:2016-02-11 15:14:47
【问题描述】:
我正在使用自制主题,试图使其重量轻,用于特定网站。到目前为止,在开发中,我只是使用 index.php 文件来查看页面和帖子,工作顺利且简单。不过,我添加了自定义帖子类型,当我尝试打开单个自定义帖子时,会加载 index.php 文件,但在其中的循环中没有加载任何内容。我猜循环在高处找不到任何帖子。我的猜测是 index.php 中的某些内容,或者 register_post_type 会变得很糟糕。你怎么看?
我的 index.php(瘦身):
<?php get_header(); ?>
<div class="hero-unit">
<?php get_template_part('hero'); ?>
</div>
<?php
// Start the loop.
while ( have_posts() ) : the_post();
the_content(); //disconnected the content just to see if i get response, but nothing appears
/*get_template_part( 'content', get_post_format() ); */
// End the loop.
endwhile;
?>
<?php get_template_part('featured'); ?>
</div><!-- /.container -->
我的 register_post_type 函数:
/* Custom Post Types */
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'kalender',
array(
'labels' => array(
'name' => __( 'Kalender' ),
'singular_name' => __( 'Kalenderpost' )
),
'supports' => array(
'title',
'editor',
'custom-fields',
'thumbnail'
),
'public' => true,
'has_archive' => true,
)
);
}
知道出了什么问题吗?当我从 WP 中的上述单个帖子打开 (WP-domain)/kalender/postname URL 时,它会显示完整的主题,除了应该在循环中找到的内容。如果我尝试使用 404 响应的故障排除循环,它会激活,就像根本没有匹配的帖子一样。
【问题讨论】:
标签: wordpress wordpress-theming custom-post-type