我使用自定义帖子类型" events"。我制作了自定义页面模板page-events.php
。
我制作了一个页面" Events" (slu events
)作为存档页面。
选择"活动"作为页面模板。
什么都不会显示,但当我切换到默认的页面模板时,"事件"万事如意。
WP正文班级显示events-template-default single single-events
所以,我不是真的为什么?
我的设置:
<?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(); ?>
<?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 );
?>