【问题标题】:wordpress custom post type template file loop 404wordpress 自定义帖子类型模板文件循环 404
【发布时间】: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


    【解决方案1】:

    如果您使用的是 Apache 服务器?

    确保启用了重写模块。

    另外,检查 .htaccess 文件是否有任何问题。

    【讨论】:

    • 谢谢!到目前为止,该项目只是 Mamp 上的本地项目,所以是的,它是 Apache。我会尝试,也可以通过在我的测试服务器上安装安装来测试,看看它是否不同。
    猜你喜欢
    • 2022-07-20
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    相关资源
    最近更新 更多