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


Category listing pages for Custom post type

我将自定义帖子类型添加到名为"项目"的主题中。它使用内置的类别分类法,但无法在前端列出这些项目类别帖子。

这是我用于创建自定义帖子类型的代码

// Register 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 );

任何帮助不胜感激

您需要

查询您的帖子类型,例如:$query = new WP_Query( 'post_type=projects' );

我什至建议您为您的帖子类型创建一个简码,该代码执行自定义查询并列出帖子。

您可以在此处和此处找到更多信息。