WordPress-两个不同类别的两个不同职位,但名称相同

时间:2018-11-14 21:04:38

标签: php wordpress

我在wordpress中创建了一个自定义帖子类型。问题是如果我在两个不同类别中有两个不同职位,但标题相同,例如当我的永久链接配置为%category%/ TITLE时,TITLE-2就是其中的TITLE,而只是TITLE。我还注意到,如果我在CATEGORY1 / TITLE1中发布了帖子,则只需将其放入浏览器CATEGORY2 / TITLE1中,当我将其仅放在CATEGORY1中时,我将看到该帖子分为两个类别。我该如何解决这个问题?

在function.php中有我的代码

function create_post_type_html5()
{
    register_taxonomy_for_object_type('category', 'html5-blank'); // Register Taxonomies for Category
    register_taxonomy_for_object_type('post_tag', 'html5-blank');
    register_post_type('html5-blank', // Register Custom Post Type
        array(
        'labels' => array(
            'name' => __('Turnieje', 'html5blank'), // Rename these to suit
            'singular_name' => __('Turnieje', 'html5blank'),
            'add_new' => __('Dodaj nowy', 'html5blank'),
            'add_new_item' => __('Dodaj nowy turniej', 'html5blank'),
            'edit' => __('Edytuj', 'html5blank'),
            'edit_item' => __('Edytuj turniej', 'html5blank'),
            'new_item' => __('Dodaj nowy turniej', 'html5blank'),
            'view' => __('Zobacz turniej', 'html5blank'),
            'view_item' => __('Zobacz turniej', 'html5blank'),
            'search_items' => __('Wyszukaj turniej', 'html5blank'),
            'not_found' => __('Nie znaleziono żadnego turnieju', 'html5blank'),
            'not_found_in_trash' => __('Nie znaleziono żadnego turnieju w koszu', 'html5blank')
        ),
        'public' => true,
        'hierarchical' => false, // Allows your posts to behave like Hierarchy Pages
        'has_archive' => false,
        'rewrite' => array('slug' => 't/%category%', 'with_front' => false),
        'supports' => array(
            'title',
            'editor',
            'excerpt',
            'thumbnail'
        ), // Go to Dashboard Custom HTML5 Blank post for supports
        'can_export' => true, // Allows export in Tools > Export
        'taxonomies' => array(
            'post_tag',
            'category'
        ) // Add Category and Post Tags support
    ));
}

add_filter('post_type_link', 'projectcategory_permalink_structure', 10, 4);
function projectcategory_permalink_structure($post_link, $post, $leavename, $sample) {
    if (false !== strpos($post_link, '%category%')) {
        $category_type_term = get_the_terms($post->ID, 'category');
        if (!empty($category_type_term))
            $post_link = str_replace('%category%', array_pop($category_type_term)->
            slug, $post_link);
        else
            $post_link = str_replace('%category%', 'uncategorized', $post_link);
    }
    return $post_link;
}

0 个答案:

没有答案