Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WP-自定义帖子类型中的类别_Php_Wordpress_Custom Post Type_Categories - Fatal编程技术网

Php WP-自定义帖子类型中的类别

Php WP-自定义帖子类型中的类别,php,wordpress,custom-post-type,categories,Php,Wordpress,Custom Post Type,Categories,我用缩略图、标签和。。。类别 我在单个自定义帖子页面中显示类别列表时遇到问题。_类();显示主要帖子类型而非自定义帖子类型的类别列表 functions.php // Register new custom post category - blog function blog_post_type() { $labels = array( 'name' => _x( 'Blog', 'post type general name' ),

我用缩略图、标签和。。。类别

我在单个自定义帖子页面中显示类别列表时遇到问题。_类();显示主要帖子类型而非自定义帖子类型的类别列表

functions.php

//  Register new custom post category - blog

function blog_post_type() {
    $labels = array(
        'name'               => _x( 'Blog', 'post type general name' ),
        'singular_name'      => _x( 'Blog', 'post type singular name' ),
        'add_new'            => _x( 'Dodaj', 'post' ),
        'add_new_item'       => __( 'Dodaj Post' ),
        'edit_item'          => __( 'Edytuj Post' ),
        'new_item'           => __( 'Nowy Post' ),
        'all_items'          => __( 'Wszystkie Posty' ),
        'view_item'          => __( 'View Post' ),
        'search_items'       => __( 'Szuakj postu' ),
        'not_found'          => __( 'Nie znaleziono' ),
        'not_found_in_trash' => __( 'Nie znaleziono w koszu' ), 
        'parent_item_colon'  => '',
        'menu_name'          => 'Blog'
    );
    $args = array(
        'labels'        => $labels,
        'description'   => 'Wpisy na blogu',
        'public'        => true,
        'menu_position' => 5,
        'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
        'has_archive'   => true,
        'hierarchical' => true,
        'taxonomies' => array('post_tag', 'category'),
    );
    register_post_type( 'blog', $args );    
}
add_action( 'init', 'blog_post_type' );

function blog_taxonomies() {
    $labels = array(
        'name'              => _x( 'Kategorie', 'taxonomy general name' ),
        'singular_name'     => _x( 'Kategoria', 'taxonomy singular name' ),
        'search_items'      => __( 'Szukaj Kategorii' ),
        'all_items'         => __( 'Wszystkie Kategorie' ),
        'parent_item'       => __( 'Nadrzędna Kategoria' ),
        'parent_item_colon' => __( 'Nadrzędna Kategoria:' ),
        'edit_item'         => __( 'Edytuj Kategorię' ), 
        'update_item'       => __( 'Zaktualizuj Kategorię' ),
        'add_new_item'      => __( 'Dodaj Nową Kategorię' ),
        'new_item_name'     => __( 'Nowa Kategoria' ),
        'menu_name'         => __( 'Kategorie' ),
    );
    $args = array(
        'labels' => $labels,
        'public' => true,
        'hierarchical' => true,
        'taxonomies' => array('category'),
    );
    register_taxonomy( 'blog_category', 'blog', $args );
}
add_action( 'init', 'blog_taxonomies', 0 );
和我的自定义帖子类型循环:

$args = array(
              'post_type' => 'Blog',
              'cat' => $catID,
              'author' => $authorID
              );

          $temp = $wp_query;
          $wp_query= null;
          $wp_query = new WP_Query($args);

if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); 

CONTENT with the_category();

endwhile; 

else: 

endif; 
有什么想法吗

谢谢


Silon

当您注册帖子类型时,您将其注册到类别
post\u标签
类别

function blog_post_type() {
    // some labels
    $args = array(
        // more args
        'taxonomies' => array('post_tag', 'category'),
    );
    register_post_type( 'blog', $args );    
}
但稍后,您将注册一个名为
blog\u category
的分类法(请参见
注册\u分类法的第一个参数

function blog_taxonomies() {
    //some labels
    $args = array(
        // more args
        'taxonomies' => array('category'),
    );
    register_taxonomy( 'blog_category', 'blog', $args );
}
最重要的是,在
register\u taxonomy
call()的参数中使用了错误的参数(分类法)

这可能就是为什么类别分类法不能正确地适用于您的帖子类型