自定义发布类型注册为页面发布类型

时间:2013-07-23 作者:Jake Lisby

我无法正确注册自定义帖子类型。它似乎正在识别为页面帖子类型并使用该模板。我也无法访问它的存档页。知道怎么了吗?

add_action( \'init\', \'register_cpt_women\' );

function register_cpt_women() {

    $womenLabels = array( 
        \'name\' => _x( \'The Women\', \'women\' ),
        \'singular_name\' => _x( \'The Women\', \'women\' ),
        \'add_new\' => _x( \'Add New\', \'women\' ),
        \'add_new_item\' => _x( \'Add New Woman\', \'women\' ),
        \'edit_item\' => _x( \'Edit Woman\', \'women\' ),
        \'new_item\' => _x( \'New Woman\', \'women\' ),
        \'view_item\' => _x( \'View Woman\', \'women\' ),
        \'search_items\' => _x( \'Search Women\', \'women\' ),
        \'not_found\' => _x( \'No women found\', \'women\' ),
        \'not_found_in_trash\' => _x( \'No women found in Trash\', \'women\' ),
        \'parent_item_colon\' => _x( \'Parent Woman:\', \'women\' ),
        \'menu_name\' => _x( \'The Women\', \'women\' ),
    );

    $womenArgs = array( 
        \'labels\' => $womenLabels,
        \'hierarchical\' => false,
        \'description\' => \'The Women Listing\',
        \'supports\' => array( \'title\', \'editor\', \'thumbnail\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 6,
        \'menu_icon\' => \'/wp-content/themes/ssekoDesigns/assets/img/ico-jobs.png\',
        \'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( \'women\', $womenArgs );

}

2 个回复
最合适的回答,由SO网友:helgatheviking 整理而成

转到“设置”>“永久链接”,然后重新保存永久链接。初始化帖子类型时,需要刷新重写规则。

SO网友:Iftieaq

Use this code

<?php
/* Testimonial */
function dyn_testimonial_post_tipe() {
    register_post_type( \'testimonial\',
                array( 
                \'label\' => __(\'Testimonial\'), 
                \'singular_label\' => __(\'testimonial Name\'),
                \'_builtin\' => false,
                \'public\' => true, 
                \'show_ui\' => true,
                \'show_in_nav_menus\' => true,
                \'hierarchical\' => true,
                \'capability_type\' => \'page\',
                \'menu_icon\' => get_template_directory_uri() . \'/lib/post-tipe/icon/testimonial.png\',
                \'rewrite\' => array(
                    \'slug\' => \'testimonial-view\',
                    \'with_front\' => FALSE,
                ),
                \'supports\' => array(
                        \'title\',
                        \'editor\',
                        \'thumbnail\')
                        ) 
                );
    register_taxonomy(\'testimonial_category\', \'testimonial\', 
        array(
        \'hierarchical\' => true, 
        \'label\' => \'Testimonial Categories\', 
        \'singular_name\' => \'Category\', 
        "rewrite" => true, 
        "query_var" => true));
}
add_action(\'init\', \'dyn_testimonial_post_tipe\');
    // Add to admin_init function
    add_action(\'manage_testimonial_posts_custom_column\' , \'custom_testimonial_columns\', 10, 2);
    add_filter(\'manage_edit-testimonial_columns\', \'my_testimonial_columns\');
    //Add columns for Testimonial posts
function my_testimonial_columns($columns) {
    $columns = array(
        "cb" => "<input type=\\"checkbox\\" />",
        "title" => "Title",
        "testimonial_categories" => "Categories",
        "comments" => "<span><span class=\\"vers\\"><img src=\\"".get_admin_url()."images/comment-grey-bubble.png\\" alt=\\"Comments\\"></span></span>",
        "date" => "Date",

    );
    return $columns;
}
function custom_testimonial_columns( $column, $post_id ) {
    switch ( $column ) {
    case \'testimonial_categories\':
        $terms = get_the_term_list( $post_id , \'testimonial_category\' , \'\' , \',\' , \'\' );
        if ( is_string( $terms ) ) {
            echo $terms;
        } else {
            echo \'Uncategorized\';
        }
        break;
    }
}
?>
结束

相关推荐

Print out last 3 blogposts

从一个问题到另一个问题,从迪斯科到迪斯科:P我的模板要求我在模板的标题中打印出最后3篇博客的标题。它的单页布局使这些博客帖子可以链接到页面上的帖子——就在下面的某个地方。。。自从我完成wordpress新手版以来,我已经需要帮助来创建整个单页布局:Single page themeModified home page query does not yield expected results长话短说-我创建了应用程序挂钩,将原始查询更改为包含所有页面。在我们开始解析页面之前,需要处理这些博客帖子。我的尝试