1

次のカスタム投稿タイプとカスタム分類のセットアップがあります。

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 に含めることはできますか?

現在、カスタム投稿に移動すると、URL は次のようになります。

http://www.domain.com/products/(ポストネーム)/

次のようにするにはどうすればよいですか?

http://www.domain.com/(カテゴリスラッグ)/(投稿名)/

その URL にアクセスしようとしましたが、404 が表示されます。標準のアーカイブ テンプレートがセットアップされているだけです。

(そこにはあまりアクションがないので、Wordpress スタックに私の質問を移行しないでください!)


アップデート:

正しいページに移動することを確認するためだけに、以下のコードをページに配置しました。これは次のようになります。

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;
} ?>
4

1 に答える 1

1

私は以前、これを達成するためにこの記事を使用しました。によってcategory-slug、私はあなたが持っているカスタム投稿タイプの分類法を意味したと思いますか?

于 2012-10-24T12:52:47.013 に答える