Md *_*sin 3 php mysql wordpress woocommerce
我为我的WordPress网站制作了自定义模板.所以我需要动态地在我的自定义模板中显示我的产品.我怎样才能做到这一点?
这是我的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>
Run Code Online (Sandbox Code Playgroud)
================================================
另外我是简单的查询,但我没有找到添加到购物车按钮动态代码???
这是我的查询代码---->
                <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>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是--->
请帮帮我...请帮帮我...
谢谢 !!!
我已经对代码进行了必要的更改以使其工作.确保将woocommerce add-to-cart.js或add-to-cart.min.js排入页面.
<div class="all_content_shop">
<?php wc_print_notices(); ?>
<?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();
        global $product;
        $product = get_product( get_the_ID() ); //set the global product object?>
        <div class="col-md-3 single_all_c_s">
            <div class="shop_product_inner">
                <a href="<?php the_permalink() ?>">
                    <?php if ( has_post_thumbnail( get_the_ID() ) ) {
                        echo get_the_post_thumbnail( get_the_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 echo $product->get_price_html(); ?></p>
                        <?php woocommerce_template_loop_add_to_cart(); //ouptput the woocommerce loop add to cart button ?>
                    </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(); ?>
Run Code Online (Sandbox Code Playgroud)
        |   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           8689 次  |  
        
|   最近记录:  |