2017-04-18 79 views
0

我有一個自定義文章類型1級的分類,這是鏈接結構: mywebsite.com/casos-legal(顯示在後歸檔casos-legal.php )改寫自定義文章類型(含分類)URL

當我點擊任何職位: mywebsite.com/casos-legal/lima/this-is-the-post-title

在上述情況下,「利馬」是一個術語的分類。

有沒有辦法在「casos-legal」之前添加路徑?是這樣的: mywebsite.com/temas/legal/casos-legal

和: mywebsite.com/temas/legal/casos-legal/lima/this-is-the-post-title

和更好的,改變後塞只是「casos」得到這樣的: mywebsite.com/temas/legal/casos/lima/this-is-the-post-title

提前致謝!

這是怎麼看的CTP

function aprodeh_casos(){ 

$labels = array(
    'name' => 'Casos - legal', 
    'singular_name' => 'Caso', 
    'add_new' => 'Agregar', 
    'all_items' => 'Todos', 
    'add_new_item' => 'Agregar', 
    'edit_item' => 'Editar', 
    'new_item' => 'Nuevo', 
    'view_item' => 'Ver', 
    'search_item' => 'Buscar', 
    'not_found' => 'No se encontraron casos', 
    'not_found_in_trash' => 'No se encontraron casos en la papelera', 
    'parent_item_colon' => 'Parent Item', 

); 

$args = array(
    'labels' => $labels, 
    'public' => true, 
    'publicly_queryable' => true, 
    'query_var' => true, 
    'rewrite' => array('slug' => '/casos-legal/%categoria_casos%', 'with_front' => false), 
    'has_archive' => 'casos-legal', 
    'capability_type' => 'post', 
    'hierarchical' => false, 
    'supports' => array(
     'title', 
     'editor', 
     'thumbnail', 
    ), 
    'menu_position' => 5, 
    'exclude_from_search' => false, 
    'taxonomies' => array('post_tag'), 
); 
register_post_type('casos-legal',$args); 

} add_action('init','aprodeh_casos'); 

這是它的外觀的分類:

function aprodeh_casos_taxonomia(){ 

$labels = array(
    'name' => 'Categorías', 
    'singular_name' => 'Categoría', 
    'search_items' => 'Buscar categoría', 
    'all_items' => 'Todas las categorías', 
    'edit_item' => 'Editar categoría', 
    'update_item' => 'Actualizar categoría', 
    'add_new_item' => 'Agregar categoría', 
    'new_item_name' => 'Nuevo categoría', 
    'menu_name' => 'Categorías', 

); 

$args = array(

    'hierarchical' => true, 
    'labels' => $labels, 
    'show_ui' => true, 
    'show_admin_column' => true, 
    'query_var' => true, 
    'rewrite' => array('slug' => 'casos-legal', 'with_front' => false), 

); 

register_taxonomy('categoria_casos', array('casos-legal'), $args); 

} 

add_action('init', 'aprodeh_casos_taxonomia'); 

最後,該代碼爲了得到這種鏈接結構: mywebsite。 com/casos-legal/lima/This-is-post-title

function wpa_casos_permalinks($post_link, $post){ 
if (is_object($post) && $post->post_type == 'casos-legal'){ 
    $terms = wp_get_object_terms($post->ID, 'categoria_casos'); 
    if($terms){ 
     return str_replace('%categoria_casos%' , $terms[0]->slug , $post_link); 
    } 
} 
return $post_link; 
} 
add_filter('post_type_link', 'wpa_casos_permalinks', 1, 2); 

回答

0

嘗試更新

'rewrite' => array('slug' => '/casos-legal/%categoria_casos%', 'with_front' => false), 

'rewrite' => array('slug' => '/tema/legal/casos/%categoria_casos%', 'with_front' => false),