首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未找到自定义Post类型存档模板页

未找到自定义Post类型存档模板页
EN

WordPress Development用户
提问于 2016-12-19 04:52:28
回答 1查看 5.4K关注 0票数 0

以下代码为自定义post类型:

代码语言:javascript
复制
add_action( 'init', 'wpt_technology_posttype' );
function wpt_technology_posttype() {

  register_post_type( 'technology',
    array(
      'labels' => array(
        'name' => __( 'Technology Providers List' ),
        'singular_name' => __( 'Technology' ),
        'add_new' => __( 'Add Techonology Provider' ),
        'add_new_item' => __( 'Add New Technology' ),
        'edit_item' => __( 'Edit Technology' ),
        'new_item' => __( 'Add New Technology' ),
        'view_item' => __( 'View Technology' ),
        'search_items' => __( 'Search Technology' ),

        'not_found' => __( 'No News found' ),
        'not_found_in_trash' => __( 'No Technology found in trash' )
      ),
      'public' => true,
      'has_archive' =>'true',
      'hierarchical'        => true,
      'supports' => array( 'title','thumbnail','editor', 'comments' ),
      'capability_type' => 'post',
      'rewrite' => array("slug" => "techno_type"), // Permalinks format
      'menu_position' => 22,
     )
  );

  register_taxonomy('techno_type', 'technology', 
  array('hierarchical' => true, 'label' => 'Add New Technology', 'query_var' => true, 'rewrite' => true));
}

我创建了页面名存档-Technology.php。我写了剧本,但没有找到页面。如何在归档页面中显示post。我还在functions.php中使用了以下代码:

代码语言:javascript
复制
function custom_post_archive( $query ){
    if ( is_post_type_archive('technology') ) {
         include 'archive-technology.php';
    }
}
add_action('pre_get_posts','custom_post_archive');
EN

回答 1

WordPress Development用户

发布于 2016-12-20 10:53:08

我不认为你需要在这个问题上使用钩子pre_get_posts。从functions.php中删除该部分。然后将archive-technology.php放在主题根目录中。然后转到Permalinks设置页面,然后单击settings按钮。WordPress将需要重新生成.htaccess文件以使用新的归档模板。

票数 5
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/249683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档