2016-12-28 12 views
2

Woocommerce Projectsプラグインのショートコードを使用しています。ユーザーが表示しているプロジェクトと同じカテゴリにあるプロジェクトのみを表示するにはどうすればいいですか?Wordpressショートコードwoocommerceプロジェクトプラグイン

私はこのコードを使用

Visit more projects of 

<?php 
    $terms_as_text = get_the_term_list($post->ID, 'project-category'); 

    if ($terms_as_text) { 
     echo wp_strip_all_tags($terms_as_text); 
    } 
?>? 

<?php echo do_shortcode('[projects limit="3" columns="3" orderby="rand" order="desc" exclude_categories=""]'); ?> 

上にテキストが取り組んでいるが、どのように私はすべてが、shortcodeでアクティブなカテゴリを除外することができますか?私は拡張子がその機能が付属していない驚いている

<?php 
     $terms = get_terms(array(
      'taxonomy' => 'project-category', 
     )); 
     //$post_terms = wp_get_post_terms($post->ID, 'project-category'); 
     $post_terms = wp_get_post_terms($post->ID, 'project-category'); 

     $cat_string = array(); 
     $in_string = true; 
     if (!empty($terms)) { 
      foreach($terms as $term){ 
       $in_string = true; 
       foreach($post_terms as $post_term){ 
        if($post_term->name == $term->name) { 
         $in_string = false; 
        } 
       } 
       if($in_string) 
        $cat_string[] = $term->term_id ; 
      } 
     } 
     if(sizeof($cat_string) > 0) 
      $cat_string = implode(',',$cat_string); 
     else 
      $cat_string = ''; 
     echo $cat_string; 
     ?> 

     <?php echo do_shortcode('[projects limit="3" columns="3" orderby="rand" order="desc" exclude_categories="' . $cat_string . '"]'); ?> 

答えて

1

はこれを試してみてください。含めることはかなり明白です。

また、私はこれがWooCommerceの貧弱な使用であると言っています。ポートフォリオを表示する方がはるかに優れています。

とにかく、助けてください。

+1

私はプラグインを表示する簡単なプロジェクトが必要でしたが、これはそれでした。私はWoocommerceについてよく知っていませんが、通常の使用はそのためのウェブショップです。しかし、このプラグインは私のために正しいことをやって、すべてがあなたの助けを借りて今働いています(ありがとう)。 – Maanstraat

+0

@Maanstraat問題ありません。 WCをポートフォリオとして使用することは、世界の終わりではありません。私は私の解説で少し過酷だったかもしれません。 –

関連する問題