2013-08-30 85 views
0

我目前正在玩WOOCOMMERCE V2.0.13,我試圖顯示當前產品類別中的每個產品(例如,在施工頁面上的建築產品),我設法顯示當前類別中的單個產品,但是如果該產品也屬於另一類別(例如建築和環境),則當前類別會從建築或環境中分解並顯示零個產品。在當前產品類別中獲得產品

如果我可以得到一些建議/幫助顯示當前類別的產品,並允許它與多個類別的產品一起工作,我會真正幫助您和時間。

我很樂意重新編碼這整個部分,使其工作,這裏是我的代碼下面,請讓我知道,如果我錯過了什麼。

謝謝。

<ul class="products"> 
    <?php 
     global $post, $product; 
     $categ = $product - > get_categories(); 
     $categ2 = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $categ); 
    ?> 
    <?php 
     global $product; 
     $args = array('post_type' = > 'product', 'posts_per_page' = > '999', 'product_cat' = > $categ2,); 
     $loop = new WP_Query($args); 
     while ($loop - > have_posts()): $loop - > the_post(); 
     global $product; 
    ?> 
     <li> 
      <a href = "<?php echo get_permalink(); ?>"> 
       <?php 
        if (has_post_thumbnail()) { 
         $image = get_the_post_thumbnail($post - > ID, apply_filters('single_product_large_thumbnail_size', 'shop_single')); 
         $image_title = esc_attr(get_the_title(get_post_thumbnail_id())); 
         $image_link = get_permalink($product_id); 
         $attachment_count = count($product - > get_gallery_attachment_ids()); 
         echo apply_filters('woocommerce_single_product_image_html', sprintf('<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" rel="prettyPhoto'.$gallery.'">%s</a>', $image_link, $image_title, $image), $post - > ID); 
        } else { 
         echo apply_filters('woocommerce_single_product_image_html', sprintf('<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src()), $post - > ID); 
       } ?> 
      </a> 
      <div> 
       <h3> 
        <a href="<?php echo get_permalink(); ?>"><?php the_title();?></a> 
        <span> 
         <?php 
          if ($price_html = $product - > get_price_html()) { 
         ?> 
          <span class = "price"> 
           <?php echo $price_html; ?> 
          </span> 
         <?php } ?> 
        </span> 
       </h3> 
      </div> 
      <div> 
       <p> 
        <?php 
         $excerpt = get_the_excerpt(); 
         echo string_limit_words($excerpt, 15); 
        ?> 
       </p> 
      </div> 
     </li> 
    <?php endwhile; ?> 
</ul> 

Screenshot

回答

0
<?php if (have_posts()) : ?> 
     <?php woocommerce_product_loop_start(); ?> 
     <?php woocommerce_product_subcategories(); ?> 
      <div class="courses-main"> 
       <ul class="products"> 
        <?php while (have_posts()) : the_post(); ?> 
         <li> 
          <a href="<?php echo get_permalink(); ?>"> 
           <?php 
            if (has_post_thumbnail()) { 
             $image = get_the_post_thumbnail($post->ID, apply_filters('single_product_large_thumbnail_size', 'shop_single')); 
             $image_title = esc_attr(get_the_title(get_post_thumbnail_id())); 
             $image_link = get_permalink($product_id); 
             $attachment_count = count($product->get_gallery_attachment_ids()); 
             echo apply_filters('woocommerce_single_product_image_html', sprintf('<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_title, $image), $post->ID); 
            } else { 
             echo apply_filters('woocommerce_single_product_image_html', sprintf('<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src()), $post->ID); 
            } 
           ?> 
          </a> 
          <div> 
           <h3> 
            <a href="<?php echo get_permalink(); ?>"><?php the_title();?></a> 
             <span> 
              <?php if ($price_html = $product->get_price_html()) { ?> 
               <span class="price"><?php echo $price_html; ?></span> 
              <?php } ?> 
             </span> 
           </h3> 
          </div> 
          <div> 
           <p> 
            <?php 
             $excerpt = get_the_excerpt(); 
             echo string_limit_words($excerpt,15); 
            ?> 
           </p> 
          </div> 
         </li> 
       <?php endwhile;?> 
      </ul> 
     </div> 
     <?php woocommerce_product_loop_end(); ?> 
    <?php endif; ?> 
相關問題