I use the custom post type "events". I make a custom page template page-events.php.
I make a page "Events" (slug events) as archive page.
Select "Events" as page template.
Nothing will show, but when I switch over to default page template insteed of "Events" everythings works fine.
The WP body class shows events-template-default single single-events
So, I don't really why?
My settings:
page-events.php
<?php
/*
Template Name: Events
*/
?>
...
<?php
$args = array(
'post_type' => array( 'events' ),
'posts_per_page' => '-1',
'order' => 'ASC'
);
$news_query = new WP_Query( $args );
if ( $news_query->have_posts() ) : ?>
<?php while ( $news_query->have_posts() ) : ?>
<?php $news_query->the_post(); ?>
...
<?php endwhile; endif; wp_reset_postdata(); ?>
functions.php
<?php
// Register Custom Post Type "Events"
function cpt_events() {
$labels = array(
'name' => _x( 'Events', 'Post Type General Name', 'theme_mmm' ),
'singular_name' => _x( 'Events', 'Post Type Singular Name', 'theme_mmm' ),
'menu_name' => __( 'Events', 'theme_mmm' ),
'name_admin_bar' => __( 'Events', 'theme_mmm' ),
'parent_item_colon' => __( 'Events:', 'theme_mmm' ),
'all_items' => __( 'Alle Events', 'theme_mmm' ),
'add_new_item' => __( 'Event hinzufügen', 'theme_mmm' ),
'add_new' => __( 'Event hinzufügen', 'theme_mmm' ),
'new_item' => __( 'Event hinzufügen', 'theme_mmm' ),
'edit_item' => __( 'Event bearbeiten', 'theme_mmm' ),
'update_item' => __( 'Aktualisieren', 'theme_mmm' ),
'view_item' => __( 'Events ansehen', 'theme_mmm' ),
'search_items' => __( 'Suchen', 'theme_mmm' ),
'not_found' => __( 'Keine Treffer', 'theme_mmm' ),
'not_found_in_trash' => __( 'Keine Treffer', 'theme_mmm' ),
);
$args = array(
'label' => __( 'Events', 'theme_mmm' ),
'description' => __( 'Beschreibung', 'theme_mmm' ),
'labels' => $labels,
'supports' => array( 'title', 'editor' ),
'taxonomies' => array(''),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => 'dashicons-calendar-alt',
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => true,
'capability_type' => 'page',
);
register_post_type( 'events', $args );
}
add_action( 'init', 'cpt_events', 0 );
?>
page-events.phptemplate code so we can see what is in it. Also to create archives for a CPT can be done using the archive template hierarchy instead of needing to make a page in the dashboard and assign a template. - William Patton