Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 职位类别及;分类相同的slug问题_Php_Wordpress_Custom Post Type_Taxonomy - Fatal编程技术网

Php 职位类别及;分类相同的slug问题

Php 职位类别及;分类相同的slug问题,php,wordpress,custom-post-type,taxonomy,Php,Wordpress,Custom Post Type,Taxonomy,我正在研究post_类型和分类法。我为其主页创建了一个页面模板“foo_template.php”,在主页中我编写了一个查询,显示了所有分类法和相关的(5)五篇文章。当我点击任何分类法时,新页面会打开,它会显示所有点击分类法的帖子标题,它的slug是“foo_taxonomy”,我也会为它创建一个页面“taxonomy-foo_post.php”,当我点击任何标题时,它会进入我为它创建的单个页面“single-foo_post.php”,它的slug是“foo_post” 现在的主要问题是,我希

我正在研究post_类型和分类法。我为其主页创建了一个页面模板“foo_template.php”,在主页中我编写了一个查询,显示了所有分类法和相关的(5)五篇文章。当我点击任何分类法时,新页面会打开,它会显示所有点击分类法的帖子标题,它的slug是“foo_taxonomy”,我也会为它创建一个页面“taxonomy-foo_post.php”,当我点击任何标题时,它会进入我为它创建的单个页面“single-foo_post.php”,它的slug是“foo_post”

现在的主要问题是,我希望帖子类型和分类法slug是相同的,当我这样做时,我的页面布局会受到干扰,它会转到archive.php

我的朋友给了我一些我写的代码,其中post_类型和分类slug是相同的,当我点击分类时,页面以新的相同slug打开,但当我点击单个页面的post标题时,它显示“page not found”

有什么问题我不明白

这是我的密码:

职位类型和分类代码:

add_action('init', 'foo_articles');
function foo_articles() {
    register_post_type('foo_knowledgebase', array(
        'labels' => array(
            'name' => 'Articles',
            'singular_name' => 'Article'
        ),
        'public' => true,
        'rewrite' => array(
            'slug' => 'My_slug')
    ));
}

add_action( 'init', 'foo_taxonomies', 0 );
function foo_taxonomies() {
    register_taxonomy('foo_taxonomy', array('My_slug'), array(
        'labels' => array(
            'name' => 'Articles Category'
        ),
        'show_ui' => true,
        'show_admin_column' => true,
        'show_tagcloud' => FALSE,
        'hierarchical' => true,
        'rewrite' => array('slug' => 'My_slug', 'with_front' => TRUE)
    ));
}
对于相同的段塞代码:

$rules = array();
    $taxonomies = get_taxonomies(array('_builtin' => false), 'objects');
    $post_types = get_post_types(array('public' => true, '_builtin' => false), 'names');

    foreach ($post_types as $post_type) {
        $post_type_data = get_post_type_object( $post_type );
        $post_type_slug = $post_type_data->rewrite['slug'];

        foreach ($taxonomies as $taxonomy) {
            if ($taxonomy->object_type[0] == $post_type_slug) {
                    $categories = get_categories(array('type' => $post_type_slug, 'taxonomy' => $taxonomy->name, 'hide_empty' => 0));
                    /* @var $category type */
                    foreach ($categories as $category) {
                        $rules[$post_type_slug . '/' . $category->slug . '/?$'] = 'index.php?' . $category->taxonomy . '=' . $category->slug;
                    }
            }
        }
    }
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_filter( 'generate_rewrite_rules', 'taxonomy_slug_rewrite' );
我的朋友说这个代码对他有用,但我现在不知道这里发生了什么,我复制了相同的代码

此条件也设置为真

if ($taxonomy->object_type[0] == $post_type_slug)
但我不知道为什么我的鼻涕虫不起作用


请帮助我

要实现什么目标,您需要在自定义帖子类型之前定义自定义分类法。 这种方法会起作用,但在不太可能的情况下,您的分类法和您的帖子将具有相同的slug,您将无法查看条目

e、 g.如果您将有一个分类术语“press”和一个标题为“press”的CPT