简体   繁体   English

自定义帖子类型的类别列表页面

[英]Category listing pages for Custom post type

I added the custom post type to my theme named Projects. 我将自定义帖子类型添加到名为Projects的主题中。 It's using built in category taxonomy but can't get those project categories posts listed on front end. 它使用内置的类别分类法,但无法在前端列出这些项目类别的帖子。

Here is my the code that I used for creating the custom post type 这是我用于创建自定义帖子类型的代码

// Register Custom Post Type

function custom_post_type() { 函数custom_post_type(){

$labels = array(
    'name'                => 'Projects',
    'singular_name'       => 'Project',
    'menu_name'           => 'Projects',
    'parent_item_colon'   => 'Parent Item:',
    '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(
    'label'               => 'projects',
    'description'         => 'Project Description',
    'labels'              => $labels,
    'supports'            => array( 'title', 'editor', 'excerpt', 'thumbnail', ),
    'taxonomies'          => array( 'category', 'post_tag' ),
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'page',
);
register_post_type( 'projects', $args );

Any help is appreciated 任何帮助表示赞赏

You need to query for your post type like: $query = new WP_Query( 'post_type=projects' ); 您需要查询您的帖子类型,例如: $query = new WP_Query( 'post_type=projects' );

I'd even recommend that you create a shortcode for your post type, that does the custom query and lists the posts. 我什至建议您为您的帖子类型创建一个简码,该短代码会进行自定义查询并列出帖子。

You can find out more here and here . 您可以在这里这里找到更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM