Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.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
如何在wordpress中显示自定义帖子类型类别?_Wordpress_Custom Post Type_Taxonomy - Fatal编程技术网

如何在wordpress中显示自定义帖子类型类别?

如何在wordpress中显示自定义帖子类型类别?,wordpress,custom-post-type,taxonomy,Wordpress,Custom Post Type,Taxonomy,最近,我在wordpress中创建了一个自定义的post类型,并添加了名为category和tags的分类法。新创建的自定义帖子类型显示在我的wordpress的管理面板中。它还允许我添加post并从数据库中获取它们,并执行默认wordpress post提供的所有操作。我唯一不能做的事情是,每当我从自定义帖子类型查看新创建的类别时,它都会将我重定向到没有找到任何内容的页面 然而,几个月前,我在wordpress.org论坛上找到了一个解决方案,有人建议将flush\u rewrite\u ru

最近,我在wordpress中创建了一个自定义的post类型,并添加了名为category和tags的分类法。新创建的自定义帖子类型显示在我的wordpress的管理面板中。它还允许我添加post并从数据库中获取它们,并执行默认wordpress post提供的所有操作。我唯一不能做的事情是,每当我从自定义帖子类型查看新创建的类别时,它都会将我重定向到没有找到任何内容的页面

然而,几个月前,我在wordpress.org论坛上找到了一个解决方案,有人建议将
flush\u rewrite\u rules()
放在
register\u post\u type()的正下方语句。我试图实现它来解决我的问题,但没有成功


有谁能帮我解决这个问题吗?

让我举例说明:

在function.php中创建带有职业名称的自定义帖子

function career() {
    $args = array( 'public' => true, 'label' => 'Career', 'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
 'thumbnail' => true,
 'supports' => array( 'title', 'editor','thumbnail', 'excerpt','revisions', 'custom-fields')
 );
    register_post_type( 'career', $args );
}
add_action('init', 'career');
//create two taxonomies, genres and writers for the post type "book"
function create_career_taxonomies() 
{
  // Add new taxonomy, make it hierarchical (like categories)

  register_taxonomy('career_cat',array('career'), array(
    'hierarchical' => true,

    'show_ui' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'career_cat' ),
  ));

}


//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_career_taxonomies', 0 );
现在创建该帖子的texonomy

function career() {
    $args = array( 'public' => true, 'label' => 'Career', 'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
 'thumbnail' => true,
 'supports' => array( 'title', 'editor','thumbnail', 'excerpt','revisions', 'custom-fields')
 );
    register_post_type( 'career', $args );
}
add_action('init', 'career');
//create two taxonomies, genres and writers for the post type "book"
function create_career_taxonomies() 
{
  // Add new taxonomy, make it hierarchical (like categories)

  register_taxonomy('career_cat',array('career'), array(
    'hierarchical' => true,

    'show_ui' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'career_cat' ),
  ));

}


//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_career_taxonomies', 0 );
让我们用它的帖子来调用DynamicCategory确保您的类别至少有一篇帖子。

    <?php
     $taxonomy = 'career_cat';
     $tax_terms = get_terms($taxonomy);

      foreach ($tax_terms as $tax_term) { ?>
        <ul>
           <li>
         <?php $query =  query_posts("post_type=career&career_cat=".$tax_term->name);
 if ( have_posts() ) { while ( have_posts() ) { the_post(); $post = get_post();  ?>
              <ul><li class="fl tr">
                   <a href="<?php the_permalink(); ?>"><?php  the_title(); ?></a>
                  </li></ul>
                  <?php }} ?>
                 </li>
                </ul>
       <?php  }   ?>


请检查是否有人能帮我……我正在等待您的答案:-)