2017-06-21 7 views
2

このコードを使用してカスタム投稿カテゴリを階層的に表示していますが、これまですべてが機能していますが、達成したいのはこれらのカテゴリをプレーンテキスト(<a href="..."なし)として表示することです。誰も助けることができますか? https://developer.wordpress.org/reference/functions/wp_list_categories/カスタム投稿カテゴリを計画テキストとして表示

$分類:次の関数を経由して、

$terms = trim(implode(',', (array) $terms), ' ,'); 
$categories = get_categories(array('include'=>$terms,'taxonomy'=>'produkte_kategorie')); 

foreach ($categories as $category) { 
    echo $category->cat_name; 
} 

答えて

0

あなたが行うことができます= 'カテゴリ';

//投稿に割り当てられた用語IDを取得します。$ post_terms = wp_get_object_terms($ post-> ID、$ taxonomy、array( 'fields' => 'ids'));

//リンク間の区切り文字。 $ separator = '、';

あれば、あなたのフィードバックのための{

$term_ids = implode(',' , $post_terms); 

$terms = wp_list_categories(array(
    'title_li' => '', 
    'style' => 'none', 
    'echo'  => false, 
    'taxonomy' => $taxonomy, 
    'include' => $term_ids 
)); 

$terms = rtrim(trim(str_replace('<br />', $separator, $terms)), $separator); 

// Display post categories. 
echo $terms; 

どうもありがとう

+0

私はこのエラーを取得しています(空($ post_terms)& & is_wp_error($ post_terms)!!):エラー解析:構文エラーが発生し、予期しない '=>'(T_DOUBLE_ARROW) – gencdoda

+0

配列を渡すのを忘れて、コードに追加しました –

0

は実はこれが私のために働いていなかったが、私はワードプレスのコーデックスから、このコードで溶液を作ったこと

    $taxonomy = 'produkte_kategorie'; // change this to your taxonomy 
        $terms = wp_get_post_terms($post->ID, $taxonomy, array("fields" => "ids")); 
        if($terms) { 
        echo '<ul class="p-kategorie">'; 
        $terms = trim(implode(',', (array) $terms), ' ,'); 
        wp_list_categories('title_li=&taxonomy=' . $taxonomy . '&include=' . $terms); 
        echo '</ul>'; 
        } 
関連する問題