doudou7361 2014-07-29 10:13
浏览 54
已采纳

Wordpress Woocommerce产品的简码

enter image description hereI am just checking in to see if anyone knows a way of just showing a products description via short code or any other method without the image and description etc.

I have numerous articles regarding woo-commerce short code but nothing this specific. I am using this as part of a slider which I do not want the image of the product to show in there so just the product name and description and maybe price?

so I am editing archive-product.php

I have a slider within this page which I want to show a 'featured item' but with no image just the description:

  <?php
/**
 * The Template for displaying product archives, including the main shop page which is a post type archive.
 *
 * Override this template by copying it to yourtheme/woocommerce/archive-product.php
 *
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     2.0.0
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

get_header( 'shop' ); ?>








<!-- Featured product title and desciption -->

<?php
ini_set('max_execution_time', 0); //I saw maximum execution time error on your image - this is for that
$args = array(
   'post_status'    => 'publish',
   'post_type'      => 'product',
   'meta_value'     => 'yes',
   'posts_per_page' => 1,
   'product_cat'    => 'grammar'
);

$product_query = new WP_Query( $args );

?>
<div class="shopBanner">
    <div class="container">
    <div id="myCarousel" class="carousel slide">
        <div class="carousel-inner">
            <div class="active item" id="id1">

                <div class="section group">
                   <?php  if ($product_query->have_posts()) : ?>
                      <?php while ($product_query->have_posts()) : ?>
                          <div class="col span_2_of_3">
                          <h1><?php echo $product_query->post->post_title; ?></h1>
                          <h2 style="margin-top:-20px;">
                              <?php echo $product_query->post->post_excerpt; ?>
                          </h2>
                          </div>
                       <?php endwhile; ?>
                    <?php endif; ?>
                    <div class="col span_1_of_3">
                        <span class="icon lush-comments" id="heroIcon"></span>
                    </div>

                </div> 
            </div> 
        </div>
    </div>
    </div>             
</div>  






    <!-- Link button to featured product -->

           <div class="section1" id="section1">
            <div class="container">
            <button class="mainbtn" style="float: left; margin-top: -82px;">View product</button>
                <div class="section group">
        <div class="col span_2_of_3">
              Take a look of our range of publications. Selected publications can be purchased via a download also.


        </div>
        <div class="col span_1_of_3">
        <div style="float:right;">
        <a href="https://twitter.com/" target="_blank"><button class="social" style="background-image:url(img/twitterIcon.png);"></button></a>
        <a href="https://www.facebook.com/" target="_blank"><button class="social" style="background-image:url(img/facebookIcon.png);"></button></a>
        </div>
        </div>



            </div>
        </div>
        </div>




    <div class="section1"  style="padding: 0px 0 50px 0;">   
        <div class="container">
            <div style="background-color: #fff; width:100%; color: #777777;">
                <div style="padding: 20px; margin-bottom:-15px;">      



        <?php
            /**
             * woocommerce_before_main_content hook
             *
             * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
             * @hooked woocommerce_breadcrumb - 20
             */
            do_action( 'woocommerce_before_main_content' );
        ?>





            <!--<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>

                        <h3 style="color: #1dae5e; text-shadow:none; font-weight:600; font-size: 1.3em; margin-bottom:20px;"><?php woocommerce_page_title(); ?></h3>

            <?php endif; ?>-->



            <span style="float: right; margin-top:-40px;">

            <a class="shopNav" href="?post_type=product">Back to Shop</a>&nbsp;&nbsp;&nbsp;
            <a class="shopNav" href="?page_id=13">My Account</a>&nbsp;&nbsp;&nbsp;
            <a class="shopNav" href="?page_id=11">Basket</a>&nbsp;&nbsp;&nbsp;
            <a class="shopNav" href="?page_id=12">Checkout</a>

            </span>




      </div></div></div></div>  













    <div class="section1" style="padding: 40px 0 50px 0;">   
        <div class="container">
            <div style="background-color: #fff; width:100%; color: #777777;">
                <div style="padding: 20px;">           





            <?php do_action( 'woocommerce_archive_description' ); ?>

            <?php if ( have_posts() ) : ?>

                <?php
                    /**
                     * woocommerce_before_shop_loop hook
                     *
                     * @hooked woocommerce_result_count - 20
                     * @hooked woocommerce_catalog_ordering - 30
                     */
                    do_action( 'woocommerce_before_shop_loop' );
                ?>

                <?php woocommerce_product_loop_start(); ?>

                    <?php woocommerce_product_subcategories(); ?>

                    <?php while ( have_posts() ) : the_post(); ?>

                        <?php wc_get_template_part( 'content', 'product' ); ?>

                    <?php endwhile; // end of the loop. ?>

                <?php woocommerce_product_loop_end(); ?>

                <?php
                    /**
                     * woocommerce_after_shop_loop hook
                     *
                     * @hooked woocommerce_pagination - 10
                     */
                    do_action( 'woocommerce_after_shop_loop' );
                ?>

            <?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>

                <?php wc_get_template( 'loop/no-products-found.php' ); ?>

            <?php endif; ?>

        <?php
            /**
             * woocommerce_after_main_content hook
             *
             * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
             */
            do_action( 'woocommerce_after_main_content' );
        ?>

        <?php
            /**
             * woocommerce_sidebar hook
             *
             * @hooked woocommerce_get_sidebar - 10
             */
            do_action( 'woocommerce_sidebar' );
        ?>


            </div>
        </div>    
     </div>   
       </div> 



    <?php get_footer( 'shop' ); ?>
  • 写回答

1条回答 默认 最新

  • du77887 2014-07-30 08:26
    关注

    Below code will get the 10 products which are in grammer category and status is published. May be this will help.

    <?php
    /**
     * The Template for displaying product archives, including the main shop page which is a post type archive.
     *
     * Override this template by copying it to yourtheme/woocommerce/archive-product.php
     *
     * @author      WooThemes
     * @package     WooCommerce/Templates
     * @version     2.0.0
     */
    
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    get_header( 'shop' ); ?>
    
    <!-- Featured product title and desciption -->
    
        <?php
        ini_set('max_execution_time', 0); //I saw maximum execution time error on your image - this is for that
        $args = array(
           'post_status'    => 'publish',
           'post_type'      => 'product',
           'meta_value'     => 'yes',
           'posts_per_page' => 10,
           'product_cat'    => 'grammar'
        );
        $product_query = new WP_Query( $args );
        ?>
        <div class="shopBanner">
            <div class="container">
            <div id="myCarousel" class="carousel slide">
                <div class="carousel-inner">
                    <div class="active item" id="id1">
                        <div class="section group">
                            <?php while ( $product_query->have_posts() ) : $product_query->the_post(); global $product; ?>
                                  <div class="col span_2_of_3">
                                  <h1><?php the_title(); ?></h1>
                                  <h2 style="margin-top:-20px;">
                                      <?php echo apply_filters( 'woocommerce_short_description', $product->post->post_excerpt ); ?>
                                  </h2>
                                  </div>
                            <?php endwhile; ?>
                            <div class="col span_1_of_3">
                                <span class="icon lush-comments" id="heroIcon"></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            </div>
        </div>
        <!-- Link button to featured product -->
    
        <div class="section1" id="section1">
            <div class="container">
                <button class="mainbtn" style="float: left; margin-top: -82px;">View product</button>
                    <div class="section group">
                <div class="col span_2_of_3">
                  Take a look of our range of publications. Selected publications can be purchased via a download also.
                </div>
                <div class="col span_1_of_3">
                    <div style="float:right;">
                    <a href="https://twitter.com/" target="_blank"><button class="social" style="background-image:url(img/twitterIcon.png);"></button></a>
                    <a href="https://www.facebook.com/" target="_blank"><button class="social" style="background-image:url(img/facebookIcon.png);"></button></a>
                    </div>
                </div>
                </div>
            </div>
        </div>
    
        <div class="section1"  style="padding: 0px 0 50px 0;">
            <div class="container">
                <div style="background-color: #fff; width:100%; color: #777777;">
                    <div style="padding: 20px; margin-bottom:-15px;">
                        <?php
                            /**
                             * woocommerce_before_main_content hook
                             *
                             * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
                             * @hooked woocommerce_breadcrumb - 20
                             */
                            do_action( 'woocommerce_before_main_content' );
                        ?>
    
                        <?php //if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
            <!--                        <h3 style="color: #1dae5e; text-shadow:none; font-weight:600; font-size: 1.3em; margin-bottom:20px;"><?php woocommerce_page_title(); ?></h3>-->
                        <?php //endif; ?>
    
                        <span style="float: right; margin-top:-40px;">
                            <a class="shopNav" href="?post_type=product">Back to Shop</a>&nbsp;&nbsp;&nbsp;
                            <a class="shopNav" href="?page_id=13">My Account</a>&nbsp;&nbsp;&nbsp;
                            <a class="shopNav" href="?page_id=11">Basket</a>&nbsp;&nbsp;&nbsp;
                            <a class="shopNav" href="?page_id=12">Checkout</a>
                        </span>
                    </div>
                </div>
            </div>
        </div>
    
        <div class="section1" style="padding: 40px 0 50px 0;">
            <div class="container">
                <div style="background-color: #fff; width:100%; color: #777777;">
                    <div style="padding: 20px;">
    
                <?php do_action( 'woocommerce_archive_description' ); ?>
    
                <?php if ( have_posts() ) : ?>
    
                    <?php
                        /**
                         * woocommerce_before_shop_loop hook
                         *
                         * @hooked woocommerce_result_count - 20
                         * @hooked woocommerce_catalog_ordering - 30
                         */
                        do_action( 'woocommerce_before_shop_loop' );
                    ?>
    
                    <?php woocommerce_product_loop_start(); ?>
    
                        <?php woocommerce_product_subcategories(); ?>
    
                        <?php while ( have_posts() ) : the_post(); ?>
    
                            <?php wc_get_template_part( 'content', 'product' ); ?>
    
                        <?php endwhile; // end of the loop. ?>
    
                    <?php woocommerce_product_loop_end(); ?>
    
                    <?php
                        /**
                         * woocommerce_after_shop_loop hook
                         *
                         * @hooked woocommerce_pagination - 10
                         */
                        do_action( 'woocommerce_after_shop_loop' );
                    ?>
    
                <?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>
    
                    <?php wc_get_template( 'loop/no-products-found.php' ); ?>
    
                <?php endif; ?>
    
            <?php
                /**
                 * woocommerce_after_main_content hook
                 *
                 * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
                 */
                do_action( 'woocommerce_after_main_content' );
            ?>
    
            <?php
                /**
                 * woocommerce_sidebar hook
                 *
                 * @hooked woocommerce_get_sidebar - 10
                 */
                do_action( 'woocommerce_sidebar' );
            ?>
                </div>
            </div>
         </div>
           </div>
    
        <?php get_footer( 'shop' ); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c