【问题标题】:Wordpress custom post type category listings not showing upWordpress 自定义帖子类型类别列表未显示
【发布时间】:2014-02-13 10:16:00
【问题描述】:

我设置了一个名为 products 的自定义帖子类型:

add_action( 'init', 'register_cpt_product' );

function register_cpt_product() 
{
    $labels = array(
        'name' => _x( 'products', 'products' ),
        'singular_name' => _x( 'product', 'products' ),
        'add_new' => _x( 'Add New', 'products' ),
        'add_new_item' => _x( 'Add New product', 'products' ),
        'edit_item' => _x( 'Edit product', 'products' ),
        'new_item' => _x( 'New product', 'products' ),
        'view_item' => _x( 'View product', 'products' ),
        'search_items' => _x( 'Search products', 'products' ),
        'not_found' => _x( 'No products found', 'products' ),
        'not_found_in_trash' => _x( 'No products found in Trash', 'products' ),
        'parent_item_colon' => _x( 'Parent product:', 'products' ),
        'menu_name' => _x( 'products', 'products' ),
    );
    $args = array(
        'labels' => $labels,
        'hierarchical' => false,
        'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ),
        'taxonomies' => array( 'category', 'post_tag' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'post'
    );

    register_post_type( 'products', $args );
}

产品与my custom archive page 一起使用。但与类别无关;我只是得到一个“未找到”。

http://drysuits.dannycheeseman.me/category/lights/

我已删除 .htaccess 并重新保存了永久链接.. (/%postname%/)

关于为什么会发生这种情况的任何想法?

【问题讨论】:

    标签: php wordpress .htaccess custom-post-type


    【解决方案1】:

    用于显示类别侧边栏的自定义分类类别列表插件。或

    您可以使用wp_list_categories 函数在您的侧边栏中创建一个列表,the Codex article 有一个代码示例,但是这样的东西应该可以工作:

    <ul>
    <?php wp_list_categories('taxonomy=products'); ?>
    </ul> 
    

    【讨论】:

    • 您好,谢谢您的意见。我说的是该类别中的实际产品。drysuits.dannycheeseman.me/category/lights 应该列出产品。没有.. ??
    • 我看到了,但侧边栏类别是博客类别而不是您的产品分类类别,因此请获取分类产品类别和分类产品列表。
    • $args = array('type' => 'product', 'child_of' => 0, 'parent' => '', 'orderby' => 'name', 'order' = > 'ASC', 'hide_empty' => 1, 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'number' => '', 'taxonomy' => 'category ', 'pad_counts' => false ); $categories = get_categories($args);
    • genearte 自己的自定义帖子类别使用:首先您添加一个简单的帖子并查看您使用默认博客类别功能的轻型类别。 deluxeblogtips.com/2010/07/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 2022-11-04
    • 1970-01-01
    • 2014-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多