Custom Post Type Archive template page not found

This following code is custom post type:add_action( 'init', 'wpt_technology_posttype' );function wp

This following code is custom post type:

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));
}

I created the page name archive-technology.php. I wrote script but page not found. How to display post in archive page.I also used following code in the functions.php:

function custom_post_archive( $query ){
    if ( is_post_type_archive('technology') ) {
         include 'archive-technology.php';
    }
}
add_action('pre_get_posts','custom_post_archive');

This following code is custom post type:

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));
}

I created the page name archive-technology.php. I wrote script but page not found. How to display post in archive page.I also used following code in the functions.php:

function custom_post_archive( $query ){
    if ( is_post_type_archive('technology') ) {
         include 'archive-technology.php';
    }
}
add_action('pre_get_posts','custom_post_archive');
Share Improve this question edited Dec 19, 2016 at 6:18 Dave Romsey 17.9k11 gold badges56 silver badges70 bronze badges asked Dec 19, 2016 at 4:52 wploverwplover 11 silver badge1 bronze badge 3
  • Please format your code properly. Also, did you flush the permalinks? – fuxia Commented Dec 19, 2016 at 5:06
  • When I used this code. I was change permalinks, But could not find the solution. Where is my coding problem? can you give any solution ? – wplover Commented Dec 20, 2016 at 7:47
  • Have you tried "archive_template" ? codex.wordpress/Plugin_API/Filter_Reference/… – Nur Hasan Commented Dec 20, 2016 at 9:53
Add a comment  | 

1 Answer 1

Reset to default 5

I don't think you need to use the hook pre_get_posts on this. Remove that part from functions.php. Then just put the archive-technology.php in themes root directory. Then go to you Permalinks settings page and hit Save Changes button. WordPress will need to regenerate the .htaccess file to use new archive template.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742300067a4417867.html

相关推荐

  • Custom Post Type Archive template page not found

    This following code is custom post type:add_action( 'init', 'wpt_technology_posttype' );function wp

    3天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信