2016-12-28 137 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活動類別?

回答

1

試試這個:

<?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 . '"]'); ?> 

我很驚訝的延長不來與該功能。似乎包括一個非常明顯的事情。

另外我得說,這是WooCommerce糟糕的用途。有很多更好的方法來顯示投資組合。

無論如何,希望有所幫助。

+1

我需要一個簡單的項目顯示插件,這是它。我不太瞭解Woocommerce,只知道它的正常使用是一個網上商店。但是這個插件對我來說是正確的,現在一切都在你的幫助下工作(謝謝)。 – Maanstraat

+0

@Mananat沒問題。將WC用作投資組合並不是世界末日。我的評論可能過於苛刻。 –