Wordpress自定义帖子类型无法正常工作

时间:2014-12-31 20:41:09

标签: php wordpress

我正在创建自定义WordPress主题,我遇到了麻烦,我创建了自定义帖子类型,当我访问自定义帖子类型时,所有样式都消失了,当我检查元素时,所有html元素都是不同于类和div,它们不包含在该自定义帖子类型文件中。

我从最后一天开始搜索Google,每个人都说这个问题是由于flush_rewrite_rules()的无关使用而发生的。并且我只在主题发生变化时使用此功能一次。

当我将固定链接从管理面板更改为默认设置时,一切正常,但是当我再次更改固定链接到postname,numeric和month&名称相同的问题发生了自定义帖子类型的所有样式,当我检查元素页面时,它显示不同的div和类。

以下是自定义帖子类型的代码。

function my_custom_post_product() {

        $labels = array(
        'name'               => _x( 'Portfolios', 'post type general name' ),
        'singular_name'      => _x( 'Portfolio', 'post type singular name' ),
        'add_new'            => _x( 'Add New', 'book' ),
        'add_new_item'       => __( 'Add New Portfolio' ),
        'edit_item'          => __( 'Edit Portfolio' ),
        'new_item'           => __( 'New Portfolio' ),
        'all_items'          => __( 'Portfolio Items' ),
        'view_item'          => __( 'View Portfolio' ),
        'search_items'       => __( 'Search Portfolio' ),
        'not_found'          => __( 'No portfolio found' ),
        'not_found_in_trash' => __( 'No portfolio found in the Trash' ), 
        'parent_item_colon'  => '',
        'menu_name'          => 'Portfolio'
    );
    $args = array(
        'labels'        => $labels,
        'description'   => 'Holds our products and product specific data',
        'public'        => true,
        'menu_position' => 40,
        'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
        'has_archive'   => true,
    );
    register_post_type( 'portfolio', $args );   

}

add_action( 'init', 'my_custom_post_product' );

function mytheme_setup_options () {
    my_custom_post_product();
    flush_rewrite_rules();
}
add_action('after_switch_theme', 'mytheme_setup_options');

任何形式的帮助都将受到赞赏 感谢

0 个答案:

没有答案