【问题标题】:Single page template not working for custom post type单页模板不适用于自定义帖子类型
【发布时间】:2014-05-02 23:03:04
【问题描述】:

我有 3 种不同类型的自定义帖子类型并使用 Redux 框架。所有人都在工作,但面临两个问题。如果我取消设置框架,它工作正常。

  1. the_permalink() 在 URL 中缺少 post_type,如下所示: 应该是http://sitename/product/abc,但得到http://sitename/abc。 它把我带到了 404 页。(在产品编辑屏幕中我得到了正确的 slug,但不是 the_permalink()

  2. 当我手动更正 url (http://sitename/product/abc) 时,它会将我带到主页。但它应该在 single-product.php 或 single.php 页面中。

我使用以下代码制作自定义帖子类型:

add_action( 'init', 'tormuz_product_cpt' );
function tormuz_product_cpt() {
    $labels = array(
        'name'               => _x( 'Products', 'post type general name' ),
        'singular_name'      => _x( 'Product', 'post type singular name' ),
        'add_new'            => _x( 'Add New', 'book' ),
        'add_new_item'       => __( 'Add New Product' ),
        'edit_item'          => __( 'Edit Product' ),
        'new_item'           => __( 'New Product' ),
        'all_items'          => __( 'All Products' ),
        'view_item'          => __( 'View Product' ),
        'search_items'       => __( 'Search Products' ),
        'not_found'          => __( 'No products found' ),
        'not_found_in_trash' => __( 'No products found in the Trash' ), 
        'parent_item_colon'  => '',
        'menu_name'          => 'Products'
    );
    $args = array(
        'labels'        => $labels,
        'description'   => 'Holds our products and product specific data',
        'public'        => true,
        'menu_position' => 45,
        'supports'      => array( 'title', 'editor', 'thumbnail' ),
        'has_archive'   => true,
    );
    register_post_type( 'product', $args );
    flush_rewrite_rules();
}

我正在运行WordPress 3.9Redux 3.2.0 没有启用dev_mode

我的永久链接结构:/%postname%/

如果可以解决,请告诉我。

提前致谢。

【问题讨论】:

    标签: wordpress url-rewriting wordpress-theming hierarchy custom-post-type


    【解决方案1】:

    通过以下方式解决: 禁用框架并再次启用它。它有效:)

    【讨论】:

    • 似乎只需要刷新您的 URL 缓存?呵呵。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    相关资源
    最近更新 更多