【问题标题】:Category listing pages for Custom post type自定义帖子类型的类别列表页面
【发布时间】:2015-01-26 20:32:04
【问题描述】:

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

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

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

感谢任何帮助

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

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

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

    您可以了解更多herehere

    【讨论】:

    • 感谢 flowb0b。像这样的查询会破坏已经是主题一部分的常规分页,还是我可以继续使用现有的分页?
    • 我建议在您的简码中添加您的分页。类似问题:stackoverflow.com/questions/11430392/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-10
    • 1970-01-01
    • 2012-11-11
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    相关资源
    最近更新 更多