我爲自己的WordPress網站製作了自定義模板。所以我需要動態地在自定義模板中顯示我的產品。我怎樣才能做到這一點?我需要添加自定義查詢並添加到購物車按鈕動態代碼在woocommerce?
這是我的HTML代碼 - >
<div class="all_content_shop">
<div class="col-md-3 single_all_c_s">
<div class="shop_product_inner">
<a href="<?php echo get_permalink($loop->post->ID) ?>">
<img src="http://jetsetbabies.com/wp-content/uploads/2006/07/100Juice_Organic_Apple_MAIN_v2.jpg" alt="Prduct Image" />
<div class="shop_product_inner_caption">
<h2>Product Title</h2>
<p>$200</p>
<a href="">Add to Cart</a>
</div>
</a>
</div>
</div>
</div>
=============================== =================
另外我是讓簡單的查詢,但我沒有找到添加到購物車按鈕動態代碼?
這是我的查詢代碼---->
<div class="all_content_shop">
<?php $new_posts = new WP_Query(array(
'post_type' => 'product', //post of page of my post type
'cat' => 0, // category id, 0 for all categories.
'posts_per_page' => 12,
'offset' => 0, //how many posts you want to eliminate from the query
'orderby' => '', // order by title or date ?
'order' => 'DESC') // order as ASC or DESC
); ?>
<?php if ($new_posts->have_posts()) :
while ($new_posts->have_posts()) :
$new_posts->the_post(); ?>
<div class="col-md-3 single_all_c_s">
<div class="shop_product_inner">
<a href="<?php echo get_permalink($loop->post->ID) ?>">
<?php if (has_post_thumbnail($loop->post->ID)) echo get_the_post_thumbnail($loop->post->ID, 'shop_single'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" />'; ?>
<div class="shop_product_inner_caption">
<h2><?php the_title(); ?></h2>
<p><?php if (! defined('ABSPATH')) exit; global $post, $product; ?> <?php echo $product->get_price_html(); ?></p>
<a href="">Add to Cart</a>
</div>
</a>
</div>
</div>
<?php endwhile;//Possibility to add else statement ?>
<?php wp_reset_postdata(); ?>
<?php else:?>
<p class="not_found">Sorry, The post you are looking is unavailable!</p>
<?php endif; wp_reset_query(); ?>
</div>
所以我的問題是--->
- 我的查詢是對還是錯?如果我的查詢是錯了,請給我正確的查詢......還有,如果我的查詢是差不多吧,所以請給我公正「添加到購物車」(http://prntscr.com/439lxj)按鈕動態Ajax代碼...
請幫我... 請幫我...
謝謝!!!
? –
感謝您的回覆。 現在我不能添加動態AJAX代碼爲「添加到購物車」按鈕 HTML代碼是=>Add to Cart –