自定义分类档案列表 - Wordpress

时间:2015-10-28 11:17:34

标签: wordpress wordpress-plugin archive taxonomy custom-taxonomy

我想显示自定义分类页面。

    $microblogging_taxonomy_slug="theme";
    $microblogging_taxonomy_singular="theme";
    $microblogging_taxonomy_plural="themes"

    $labels = array(
        'name'              => $microblogging_taxonomy_plural,
        'singular_name'     => $microblogging_taxonomy_singular,
        'search_items'      => sprintf( __( 'Search %s',LANGUAGE_MICROBLOGGING ), strtolower($microblogging_taxonomy_plural) ),
        'all_items'         => sprintf( __( 'All %s',LANGUAGE_MICROBLOGGING ), strtolower($microblogging_taxonomy_plural) ),
        'parent_item'       => sprintf( __( 'Parent %s',LANGUAGE_MICROBLOGGING ), strtolower($microblogging_taxonomy_singular) ),
        'parent_item_colon' => sprintf( __( 'Parent %s :',LANGUAGE_MICROBLOGGING ), strtolower($microblogging_taxonomy_singular) ),
        'edit_item'         => sprintf( __( 'Edit %s',LANGUAGE_MICROBLOGGING ), strtolower($microblogging_taxonomy_singular) ),
        'update_item'       => sprintf( __( 'Update %s',LANGUAGE_MICROBLOGGING ), strtolower($microblogging_taxonomy_singular) ),
        'add_new_item'      => sprintf( __( 'Add new %s',LANGUAGE_MICROBLOGGING ), strtolower($microblogging_taxonomy_singular) ),
        'new_item_name'     => sprintf( __( 'New %s',LANGUAGE_MICROBLOGGING ), strtolower($microblogging_taxonomy_singular) ),
        'menu_name'         => $microblogging_taxonomy_plural,
    );

    $args = array(
        'hierarchical'      => false,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => $microblogging_taxonomy_slug ),
    );

    register_taxonomy( MB_CUSTOM_TAX_1_NAME, array( "post" ), $args );

现在我想为这个页面“mysite.dev/theme/”创建一个模板。有可能吗?

我使用插件创建此分类法,因此我将使用像

这样的过滤器
add_filter( 'taxonomy_template', 'mb_get_custom_taxonomy_template' );

例如,我使用附加到'archive_template'过滤器挂钩的函数来替换税原始主题模板

 function mb_get_custom_post_type_template_archive($archive_template)   {
     global $taxonomy,$term,$wp_query;
     global $mb_css_js_version;

     if (is_tax() && $taxonomy == MB_CUSTOM_TAX_1_NAME) {

        $archive_template = MB_TEMPLATE_CUSTOM_TAX_1_DIR . "index.php";

     }
     else if (is_post_type_archive(MB_POST_TYPE)) {

        $archive_template = MB_TEMPLATE_ARCHIVE_DIR . "post_type_archive/index.php";
     }
     return $archive_template;
}

使用此功能,我可以查看我的插件模板

离。 mysite.dev/theme/theme-1 mysite.dev/theme/theme-2

0 个答案:

没有答案