admin管理员组文章数量:1289867
I'm trying to create a custom post type "Press" with an archive. I think I've done everything needed, yet when I go to /press url, no posts are showing up. I entered "test" in my archive-press.php, but that's not showing up either, so I assume the archive php file is not connected to the press page.
In my functions.php:
add_action( 'init', 'create_post_type' );
function create_post_type(){
register_post_type( 'press',
array(
'labels' => array(
'name' => __('Press'),
'singular_name' => __('Press Item'),
'add_new' => __('Add New'),
'add_new_item' => __('Add New Item'),
'edit_item' => __('Edit Item'),
'new_item' => __('New Item'),
'all_items' => __('All Items'),
'view_item' => __('View Items'),
'search_items' => __('Search Press'),
'not_found' => __('No Items found'),
'not_found_in_trash' => __('No Items Found in Trash'),
'parent_item_colon' => '',
'menu_name' => 'Press'
),
'labels' => $press_labels,
'publicly_queryable' => true,
'public' => true,
'show_ui' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => true,
'menu_position' => 10,
'query_var' => true,
'has_archive' =>true,
'supports' => array('title','thumbnail','excerpt')
)
);
}
My archive-press.php:
<?php get_header(); ?>
<?php
$wp_query = new WP_Query();
$wp_query -> query('post_type=press&showposts=20');
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="press-item">
<div class="press-img"><?php the_post_thumbnail('medium');?></div>
<div class="press-content">
<div class="press-title"><?php single_post_title(); ?> </div>
<div class="press-excerpt"><?php the_excerpt(); ?> </div>
</div>
</div>
<?php endwhile; ?>
<?php get_footer(); ?>
My Permalink is set to url/%category%/%postname%/
What could I be doing wrong?
I'm trying to create a custom post type "Press" with an archive. I think I've done everything needed, yet when I go to /press url, no posts are showing up. I entered "test" in my archive-press.php, but that's not showing up either, so I assume the archive php file is not connected to the press page.
In my functions.php:
add_action( 'init', 'create_post_type' );
function create_post_type(){
register_post_type( 'press',
array(
'labels' => array(
'name' => __('Press'),
'singular_name' => __('Press Item'),
'add_new' => __('Add New'),
'add_new_item' => __('Add New Item'),
'edit_item' => __('Edit Item'),
'new_item' => __('New Item'),
'all_items' => __('All Items'),
'view_item' => __('View Items'),
'search_items' => __('Search Press'),
'not_found' => __('No Items found'),
'not_found_in_trash' => __('No Items Found in Trash'),
'parent_item_colon' => '',
'menu_name' => 'Press'
),
'labels' => $press_labels,
'publicly_queryable' => true,
'public' => true,
'show_ui' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => true,
'menu_position' => 10,
'query_var' => true,
'has_archive' =>true,
'supports' => array('title','thumbnail','excerpt')
)
);
}
My archive-press.php:
<?php get_header(); ?>
<?php
$wp_query = new WP_Query();
$wp_query -> query('post_type=press&showposts=20');
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="press-item">
<div class="press-img"><?php the_post_thumbnail('medium');?></div>
<div class="press-content">
<div class="press-title"><?php single_post_title(); ?> </div>
<div class="press-excerpt"><?php the_excerpt(); ?> </div>
</div>
</div>
<?php endwhile; ?>
<?php get_footer(); ?>
My Permalink is set to url/%category%/%postname%/
What could I be doing wrong?
Share Improve this question asked Oct 27, 2014 at 19:28 Jaeeun LeeJaeeun Lee 4251 gold badge5 silver badges14 bronze badges 2 |1 Answer
Reset to default 1I generally include this chunk of code with my custom post types:
// Load the custom post type archive page template
add_filter( 'archive_template', 'posttype_archive_template' ) ;
function posttype_archive_template( $archive_template ) {
global $post;
if ( is_post_type_archive ( 'posttype' ) ) {
if(file_exists(PLUGIN_PATH. '/archive-posttype.php'))
$archive_template = PLUGIN_PATH. '/archive-posttype.php';
}
return $archive_template;
}
本文标签: Custom Post Type Archive Not Showing Posts
版权声明:本文标题:Custom Post Type Archive Not Showing Posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741485884a2381401.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'labels' => $press_labels,
the array you have defined before that is correct. Not sure but that could also be tripping things up? – Nathan Powell Commented Oct 27, 2014 at 19:47