自定义发布类型档案不显示发布

时间:2014-10-27 作者:Jaeeun Lee

我正在尝试创建一个带有存档的自定义帖子类型“Press”。我想我已经完成了所需的一切,但当我转到/按url时,没有显示任何帖子。我在存档媒体中输入了“test”。php,但也没有显示,所以我假设归档php文件没有连接到新闻页面。

在我的功能中。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\')
    )
    ); 
    }
我的存档新闻。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(); ?>
我的永久链接设置为url/%类别%/%postname%/

我会做错什么?

1 个回复
SO网友:Brendonwbrown

我通常在自定义帖子类型中包含这段代码:

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

结束

相关推荐