2012-10-24 40 views
1

我有以下的自定義後型和自定義分類設置:在url中包含分類學slu??

add_action('init', 'create_post_type'); 
function create_post_type() { 
    register_post_type('system', 
     array(
      'labels' => array(
       'name' => __('Systems'), 
       'singular_name' => __('System') 
      ), 
     'capability_type' => 'post', 
     'supports' => array('title','editor','comments'), 
     'public' => true, 
     'has_archive' => true, 
     'rewrite' => array('slug' => 'system'), 
     ) 
    ); 
} 

function news_init() { 
    register_taxonomy(
     'system', 
     'system', 
     array(
      'label' => __('Product Category'), 
      'sort' => true, 
      'hierarchical' => true, 
      'args' => array('orderby' => 'term_order'), 
      'rewrite' => array('slug' => 'products') 
     ) 
    ); 
} 
add_action('init', 'news_init'); 

是否有可能在URL中包含了自定義分類名稱?

目前,當我轉到一個自定義文章的網址是這樣的:

http://www.domain.com/products/(post-name)/

我怎樣才能使它看起來像下面?

http://www.domain.com/(category-slug)/(post-name)/

我試着去那個URL,但它只是給出了一個404我只是有標準的檔案模板設置。

(!請不要遷移我的WordPress的協議棧的問題,因爲沒有在那裏大的動作)


UPDATE:

我把下面的代碼在頁面上只是爲了確保它要正確的頁面,它會這樣:

http://www.domain.com/products/(custom-taxonomy-slug)/

這給出了404。它似乎沒有拿起模板(標準的),我也嘗試添加archive-products.php。

<?php $args = array('taxonomy' => 'my_term'); 

$terms = get_terms('system', $args); 

$count = count($terms); $i=0; 
if ($count > 0) { 
    $term_list = '<p class="my_term-archive">'; 
    foreach ($terms as $term) { 
     $i++; 
     $term_list .= '<a href="' . get_term_link($term->slug, $term->taxonomy) . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>'; 
     if ($count != $i) $term_list .= ' &middot; '; else $term_list .= '</p>'; 
    } 
    echo $term_list; 
} ?> 

回答

1

我以前用this article來達到這個目的。通過category-slug,我假設你的意思是你所擁有的自定義帖子類型的分類。

+0

我已更新我的問題。我遇到了這個環節,並嘗試過,但仍然沒有運氣。是的,分類標準很抱歉。 – Rob

+0

嘿,你最近怎麼樣? – SMacFadyen

+0

我用了2天!感謝您檢查,但仍然沒有運氣。 – Rob