php - Multiple custom post type use the same template -


i have 3 custom post type use same template:

// custom posttype photos $labels = array(     'name' => _x('photos', 'post type general name'),     'singular_name' => _x('photos', 'post type singular name'),     'menu_name' => __('photos'),     'parent_item_colon' => __('photos:'),     'all_items' => __('all items'),     'view_item' => __('view item'),     'add_new_item' => __('add new event'),     'add_new' => __('add new'),     'edit_item' => __('edit item'),     'update_item' => __('update item'),     'search_items' => __('search item'),     'not_found' => __('not found'),     'not_found_in_trash' => __('not found in trash'), ); $args = array(     'labels' => $labels,     'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'comments', 'trackbacks', 'custom-fields',),     'taxonomies' => array('post_tag'),     'hierarchical' => false,     'rewrite' => array('slug' => 'photos'),     'public' => true,     'show_ui' => true,     'show_in_menu' => true,     'show_in_nav_menus' => true,     'show_in_admin_bar' => true,     'menu_position' => 10,     'menu_icon' => 'dashicons-format-image',     'can_export' => true,     'has_archive' => false,     'exclude_from_search' => false,     'publicly_queryable' => true,     'capability_type' => 'post', ); register_post_type('photos', $args);  // custom posttype events $labels = array(     'name' => _x('events', 'post type general name'),     'singular_name' => _x('events', 'post type singular name'),     'menu_name' => __('events'),     'parent_item_colon' => __('events:'),     'all_items' => __('all items'),     'view_item' => __('view item'),     'add_new_item' => __('add new event'),     'add_new' => __('add new'),     'edit_item' => __('edit item'),     'update_item' => __('update item'),     'search_items' => __('search item'),     'not_found' => __('not found'),     'not_found_in_trash' => __('not found in trash'), ); $args = array(     'labels' => $labels,     'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'comments', 'trackbacks', 'custom-fields',),     'taxonomies' => array('post_tag'),     'hierarchical' => false,     'rewrite' => array('slug' => __('events')),     'public' => true,     'show_ui' => true,     'show_in_menu' => true,     'show_in_nav_menus' => true,     'show_in_admin_bar' => true,     'menu_position' => 10,     'menu_icon' => 'dashicons-images-alt2',     'can_export' => true,     'has_archive' => false,     'exclude_from_search' => false,     'publicly_queryable' => true,     'capability_type' => 'post', ); register_post_type('events', $args);  // custom courses      $labels = array(     'name' => _x('courses', 'post type general name'),     'singular_name' => _x('courses', 'post type singular name'),     'menu_name' => __('courses'),     'parent_item_colon' => __('courses:'),     'all_items' => __('all items'),     'view_item' => __('view item'),     'add_new_item' => __('add new item'),     'add_new' => __('add new'),     'edit_item' => __('edit item'),     'update_item' => __('update item'),     'search_items' => __('search item'),     'not_found' => __('not found'),     'not_found_in_trash' => __('not found in trash'), ); $args = array(     'labels' => $labels,     'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'comments', 'trackbacks', 'custom-fields',),     'taxonomies' => array('post_tag'),     'hierarchical' => false,     'rewrite' => array('slug' => 'courses'),     'public' => true,     'show_ui' => true,     'show_in_menu' => true,     'show_in_nav_menus' => true,     'show_in_admin_bar' => true,     'menu_position' => 10,     'menu_icon' => 'dashicons-welcome-learn-more',     'can_export' => true,     'has_archive' => false,     'exclude_from_search' => false,     'publicly_queryable' => true,     'capability_type' => 'post', ); register_post_type('courses', $args); 

i need 3 pages (or archive/taxonomy?): events show post events, page courses show post courses, page photos show post photos (they use same front-end left sidebar(have function search) , right content)

currently use template left sibar 3 pages events, courses, photos:

/* * template name: left sidebar */ 

i wanna show name of post type in each page , posts of post type. ex:

  • page events: show string 'event listing' , event
  • page courses: show string 'courses listing' , courses
  • page photos: show string 'photos listing' , photos

but template cannot post type info :(

another way, use hierachy wordpress custom post type:

  • post type events: archive-events.php
  • post type photos: archive-photos.php
  • post type courses: archive-courses.php

why 'http://mydomain.local/events/' not found? (events slug of post type events). others same.

any ideas issue?

if need more info, plz comment. , sorry bad english ^^

in every single $args array you've set has_archive false. should set 'true'. alone on way. domain http://mydomain.local/events/ should work. check out documentation 'has_archive' @ https://codex.wordpress.org/function_reference/register_post_type confirmation.

this guide: http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-post-types-archive-page-in-wordpress/ should too.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -