多次使用小部件(_W)

时间:2016-08-21 作者:sakarya

我正在尝试构建一个小部件来包含另一个小部件。

我有一个小部件类型的选择框。但是,它不能正常工作。

如您所见,我试图添加WC\\u Widget\\u产品和WC\\u Widget\\u Top\\u Rated\\u Products小部件,这些小部件具有不同的选项。但我不能使用WC\\U Widget\\u产品两次或两次以上。

/**
* Column Content (min:2 - max:3 column)
 *
 * @since  1.0.0
 * @return void 
 */
if ( ! defined( \'ABSPATH\' ) ) { exit; }

add_action( \'widgets_init\', function(){
register_widget( \'Hw_Column_Widget\' );
});

class Hw_Column_Widget extends WP_Widget {

/**
 * Sets up the widgets name etc
 */
public function __construct() {
    $widget_ops = array(
        \'classname\' => \'hw_column_widget\',
        \'description\' => \'Prostore columns widget\',
    );

    parent::__construct( \'hw_column_widget\', __( \'Home Columns\', \'theme\' ), $widget_ops );
}

/**
 * Outputs the content of the widget
 *
 * @param array $args
 * @param array $instance
 */
public function widget( $args, $instance ) {
    // outputs the content of the widget
    echo $args[\'before_widget\'];

    //the_widget($widget, $instance, $args);
    if ( ! empty( $instance[\'title_one\'] ) ) {
        $t1 = $instance[\'title_one\'];
    }

    if ( ! empty( $instance[\'title_two\'] ) ) {
        $t2 = $instance[\'title_two\'];
    }

    if ( ! empty( $instance[\'title_three\'] ) ) {
        $t3 = $instance[\'title_three\'];
    }

    $column_first = $instance[\'column_first\'];
    $column_second = $instance[\'column_second\'];
    $column_third = $instance[\'column_third\'];

    echo \'<div class="woocommerce columns-3">\';

        switch ($column_first) {
            case "recent":
                the_widget( \'WC_Widget_Products\', \'title=\'.$t1.\'\' );
                break;
            case "featured":
                the_widget( \'WC_Widget_Products\', \'title=\'.$t1.\'&show=featured\' );
                break;
            case "popular":
                the_widget( \'WC_Widget_Top_Rated_Products\', \'title=\'.$t1.\'\' ) ;
                break;
            case "onsale":
                the_widget( \'WC_Widget_Products\', \'title=\'.$t1.\'&show=onsale\' );
                break;                  
            default:
                the_widget( \'WC_Widget_Products\', \'title=\'.$t1.\'&orderby=sales\' );
        }

        switch ($column_second) {
            case "recent":
                the_widget( \'WC_Widget_Products\', \'title=\'.$t2.\'\' );
                break;
            case "featured":
                the_widget( \'WC_Widget_Products\', \'title=\'.$t2.\'&show=featured\' );
                break;
            case "popular":
                the_widget( \'WC_Widget_Top_Rated_Products\', \'title=\'.$t2.\'\' ) ;
                break;
            case "onsale":
                the_widget( \'WC_Widget_Products\', \'title=\'.$t2.\'&show=onsale\' );
                break;                  
            default:
                the_widget( \'WC_Widget_Products\', \'title=\'.$t2.\'&orderby=sales\' );
        }

        switch ($column_third) {
            case "recent":
                the_widget( \'WC_Widget_Products\', \'title=\'.$t3.\'\' );
                break;
            case "featured":
                the_widget( \'WC_Widget_Products\', \'title=\'.$t3.\'&show=featured\' );
                break;
            case "popular":
                the_widget( \'WC_Widget_Top_Rated_Products\', \'title=\'.$t3.\'\' ) ;
                break;
            case "onsale":
                the_widget( \'WC_Widget_Products\', \'title=\'.$t3.\'&show=onsale\' );
                break;                  
            default:
                the_widget( \'WC_Widget_Products\', \'title=\'.$t3.\'&orderby=sales\' );
        }           

    echo \'</div>\';

    echo $args[\'after_widget\'];
}


/**
 * Outputs the options form on admin
 *
 * @param array $instance The widget options
 */
public function form( $instance ) {
    $title= __(\'Home Columns\', \'prostore\');

    if(isset($instance[\'title_one\'])) { $title_one = esc_attr($instance[\'title_one\']); }
    if(isset($instance[\'title_two\'])) { $title_two = esc_attr($instance[\'title_two\']); }        
    if(isset($instance[\'title_three\'])) { $title_three = esc_attr($instance[\'title_three\']); }

    if(isset($instance[\'column_first\'])) { $column_first = esc_attr($instance[\'column_first\']); }
    if(isset($instance[\'column_second\'])) { $column_second = esc_attr($instance[\'column_second\']); }
    if(isset($instance[\'column_third\'])) { $column_third = esc_attr($instance[\'column_third\']); }
    ?>
    <h3>1. Kolon</h3>
    <p>
        <label for="<?php echo $this->get_field_name( \'title_one\' ); ?>"><?php _e( \'Title:\', \'prostore\' ); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id( \'title_one\' ); ?>" name="<?php echo $this->get_field_name( \'title_one\' ); ?>" type="text" value="<?php echo esc_attr( $title_one ); ?>" />
    </p>        
    <p>
        <label for="<?php echo $this->get_field_id(\'column_first\'); ?>">İçerik: 
            <select class=\'widefat\' id="<?php echo $this->get_field_id(\'column_first\'); ?>" name="<?php echo $this->get_field_name(\'column_first\'); ?>">
                <option value=\'recent\'<?php echo ($column_first==\'recent\')?\'selected\':\'\'; ?>><?php _e(\'Son Eklenen Ürünler\',\'prostore\'); ?></option>
                <option value=\'featured\'<?php echo ($column_first==\'featured\')?\'selected\':\'\'; ?>><?php _e(\'Öne Çıkan Ürünler\',\'prostore\'); ?></option>
                <option value=\'popular\'<?php echo ($column_first==\'popular\')?\'selected\':\'\'; ?>><?php _e(\'Popüler Ürünler\',\'prostore\'); ?></option> 
                <option value=\'onsale\'<?php echo ($column_first==\'onsale\')?\'selected\':\'\'; ?>><?php _e(\'İndirimli Ürünler\',\'prostore\'); ?></option> 
                <option value=\'best\'<?php echo ($column_first==\'best\')?\'selected\':\'\'; ?>><?php _e(\'Çok Satanlar\',\'prostore\'); ?></option> 
            </select>                
        </label>
    </p>
    <h3>2. Kolon</h3>
    <p>
        <label for="<?php echo $this->get_field_name( \'title_two\' ); ?>"><?php _e( \'Title:\', \'prostore\' ); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id( \'title_two\' ); ?>" name="<?php echo $this->get_field_name( \'title_two\' ); ?>" type="text" value="<?php echo esc_attr( $title_two ); ?>" />
    </p>        
    <p>
        <label for="<?php echo $this->get_field_id(\'column_second\'); ?>">İçerik: 
            <select class=\'widefat\' id="<?php echo $this->get_field_id(\'column_second\'); ?>" name="<?php echo $this->get_field_name(\'column_second\'); ?>">
                <option value=\'recent\'<?php echo ($column_second==\'recent\')?\'selected\':\'\'; ?>><?php _e(\'Son Eklenen Ürünler\',\'prostore\'); ?></option>
                <option value=\'featured\'<?php echo ($column_second==\'featured\')?\'selected\':\'\'; ?>><?php _e(\'Öne Çıkan Ürünler\',\'prostore\'); ?></option>
                <option value=\'popular\'<?php echo ($column_second==\'popular\')?\'selected\':\'\'; ?>><?php _e(\'Popüler Ürünler\',\'prostore\'); ?></option> 
                <option value=\'onsale\'<?php echo ($column_second==\'onsale\')?\'selected\':\'\'; ?>><?php _e(\'İndirimli Ürünler\',\'prostore\'); ?></option> 
                <option value=\'best\'<?php echo ($column_second==\'best\')?\'selected\':\'\'; ?>><?php _e(\'Çok Satanlar\',\'prostore\'); ?></option> 
            </select>                
        </label>
    </p>        
    <h3>3. Kolon</h3>
    <p>
        <label for="<?php echo $this->get_field_name( \'title_three\' ); ?>"><?php _e( \'Title:\', \'prostore\' ); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id( \'title_three\' ); ?>" name="<?php echo $this->get_field_name( \'title_three\' ); ?>" type="text" value="<?php echo esc_attr( $title_three ); ?>" />
    </p>        
    <p>
        <label for="<?php echo $this->get_field_id(\'column_third\'); ?>">İçerik: 
            <select class=\'widefat\' id="<?php echo $this->get_field_id(\'column_third\'); ?>" name="<?php echo $this->get_field_name(\'column_third\'); ?>">
                <option value=\'recent\'<?php echo ($column_third==\'recent\')?\'selected\':\'\'; ?>><?php _e(\'Son Eklenen Ürünler\',\'prostore\'); ?></option>
                <option value=\'featured\'<?php echo ($column_third==\'featured\')?\'selected\':\'\'; ?>><?php _e(\'Öne Çıkan Ürünler\',\'prostore\'); ?></option>
                <option value=\'popular\'<?php echo ($column_third==\'popular\')?\'selected\':\'\'; ?>><?php _e(\'Popüler Ürünler\',\'prostore\'); ?></option> 
                <option value=\'onsale\'<?php echo ($column_third==\'onsale\')?\'selected\':\'\'; ?>><?php _e(\'İndirimli Ürünler\',\'prostore\'); ?></option> 
                <option value=\'best\'<?php echo ($column_third==\'best\')?\'selected\':\'\'; ?>><?php _e(\'Çok Satanlar\',\'prostore\'); ?></option> 
            </select>                
        </label>
    </p>        
<?php
}


/**
 * Processing widget options on save
 *
 * @param array $new_instance The new options
 * @param array $old_instance The previous options
 */
public function update( $new_instance, $old_instance ) {
    // processes widget options to be saved
    foreach( $new_instance as $key => $value )
    {
        $updated_instance[$key] = sanitize_text_field($value);
    }

    return $updated_instance;
}
}

1 个回复
最合适的回答,由SO网友:sakarya 整理而成

我已经为查询编写了自定义函数。

<?php
/**
 * Column Content (min:2 - max:3 column)
 *
 * @since  1.0.0
 * @return void 
 */

if ( ! defined( \'ABSPATH\' ) ) { exit; }

add_action( \'widgets_init\', function(){
register_widget( \'Hw_Column_Widget\' );
});

class Hw_Column_Widget extends WP_Widget {

/**
 * Sets up the widgets name etc
 */
public function __construct() {
    $widget_ops = array(
        \'classname\' => \'hw_column_widget\',
        \'description\' => \'Columns widget\',
    );

    parent::__construct( \'hw_column_widget\', __( \'Home Columns\', \'theme\' ), $widget_ops );
}

/**
 * Outputs the content of the widget
 *
 * @param array $args
 * @param array $instance
 */
public function widget( $args, $instance ) {
    // outputs the content of the widget
    echo $args[\'before_widget\'];

    //the_widget($widget, $instance, $args);
    if ( ! empty( $instance[\'title_one\'] ) ) {
        $t1 = $instance[\'title_one\'];
    }

    if ( ! empty( $instance[\'title_two\'] ) ) {
        $t2 = $instance[\'title_two\'];
    }

    if ( ! empty( $instance[\'title_three\'] ) ) {
        $t3 = $instance[\'title_three\'];
    }

    $column_first = $instance[\'column_first\'];
    $column_second = $instance[\'column_second\'];
    $column_third = $instance[\'column_third\'];

    echo \'<div class="woocommerce columns-3">\';

        switch ($column_first) {
            case "recent":
                $this->recent($t1);
                break;
            case "featured":
                $this->featured($t1);
                break;
            case "popular":
                $this->popular($t1);
                break;
            case "onsale":
                $this->onsale($t1);
                break;                  
            case "best":
                $this->best($t1);
                break;
        }

        switch ($column_second) {
            case "recent":
                $this->recent($t2);
                break;
            case "featured":
                $this->featured($t2);
                break;
            case "popular":
                $this->popular($t2);
                break;
            case "onsale":
                $this->onsale($t2);
                break;                  
            case "best":
                $this->best($t2);
                break;
        }

        switch ($column_third) {
            case "recent":
                $this->recent($t3);
                break;
            case "featured":
                $this->featured($t3);
                break;
            case "popular":
                $this->popular($t3);
                break;
            case "onsale":
                $this->onsale($t3);
                break;                  
            case "best":
                $this->best($t3);
                break;
        }           

    echo \'</div>\';

    echo $args[\'after_widget\'];
}


/**
 * Outputs the options form on admin
 *
 * @param array $instance The widget options
 */
public function form( $instance ) {
    $title= __(\'Home Columns\', \'prostore\');

    if(isset($instance[\'title_one\'])) { $title_one = esc_attr($instance[\'title_one\']); }
    if(isset($instance[\'title_two\'])) { $title_two = esc_attr($instance[\'title_two\']); }        
    if(isset($instance[\'title_three\'])) { $title_three = esc_attr($instance[\'title_three\']); }

    if(isset($instance[\'column_first\'])) { $column_first = esc_attr($instance[\'column_first\']); }
    if(isset($instance[\'column_second\'])) { $column_second = esc_attr($instance[\'column_second\']); }
    if(isset($instance[\'column_third\'])) { $column_third = esc_attr($instance[\'column_third\']); }
    ?>
    <h3>1. Kolon</h3>
    <p>
        <label for="<?php echo $this->get_field_name( \'title_one\' ); ?>"><?php _e( \'Title:\', \'prostore\' ); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id( \'title_one\' ); ?>" name="<?php echo $this->get_field_name( \'title_one\' ); ?>" type="text" value="<?php echo esc_attr( $title_one ); ?>" />
    </p>        
    <p>
        <label for="<?php echo $this->get_field_id(\'column_first\'); ?>">İçerik: 
            <select class=\'widefat\' id="<?php echo $this->get_field_id(\'column_first\'); ?>" name="<?php echo $this->get_field_name(\'column_first\'); ?>">
                <option value=\'recent\'<?php echo ($column_first==\'recent\')?\'selected\':\'\'; ?>><?php _e(\'Son Eklenen Ürünler\',\'prostore\'); ?></option>
                <option value=\'featured\'<?php echo ($column_first==\'featured\')?\'selected\':\'\'; ?>><?php _e(\'Öne Çıkan Ürünler\',\'prostore\'); ?></option>
                <option value=\'popular\'<?php echo ($column_first==\'popular\')?\'selected\':\'\'; ?>><?php _e(\'Popüler Ürünler\',\'prostore\'); ?></option> 
                <option value=\'onsale\'<?php echo ($column_first==\'onsale\')?\'selected\':\'\'; ?>><?php _e(\'İndirimli Ürünler\',\'prostore\'); ?></option> 
                <option value=\'best\'<?php echo ($column_first==\'best\')?\'selected\':\'\'; ?>><?php _e(\'Çok Satanlar\',\'prostore\'); ?></option> 
            </select>                
        </label>
    </p>
    <h3>2. Kolon</h3>
    <p>
        <label for="<?php echo $this->get_field_name( \'title_two\' ); ?>"><?php _e( \'Title:\', \'prostore\' ); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id( \'title_two\' ); ?>" name="<?php echo $this->get_field_name( \'title_two\' ); ?>" type="text" value="<?php echo esc_attr( $title_two ); ?>" />
    </p>        
    <p>
        <label for="<?php echo $this->get_field_id(\'column_second\'); ?>">İçerik: 
            <select class=\'widefat\' id="<?php echo $this->get_field_id(\'column_second\'); ?>" name="<?php echo $this->get_field_name(\'column_second\'); ?>">
                <option value=\'recent\'<?php echo ($column_second==\'recent\')?\'selected\':\'\'; ?>><?php _e(\'Son Eklenen Ürünler\',\'prostore\'); ?></option>
                <option value=\'featured\'<?php echo ($column_second==\'featured\')?\'selected\':\'\'; ?>><?php _e(\'Öne Çıkan Ürünler\',\'prostore\'); ?></option>
                <option value=\'popular\'<?php echo ($column_second==\'popular\')?\'selected\':\'\'; ?>><?php _e(\'Popüler Ürünler\',\'prostore\'); ?></option> 
                <option value=\'onsale\'<?php echo ($column_second==\'onsale\')?\'selected\':\'\'; ?>><?php _e(\'İndirimli Ürünler\',\'prostore\'); ?></option> 
                <option value=\'best\'<?php echo ($column_second==\'best\')?\'selected\':\'\'; ?>><?php _e(\'Çok Satanlar\',\'prostore\'); ?></option> 
            </select>                
        </label>
    </p>        
    <h3>3. Kolon</h3>
    <p>
        <label for="<?php echo $this->get_field_name( \'title_three\' ); ?>"><?php _e( \'Title:\', \'prostore\' ); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id( \'title_three\' ); ?>" name="<?php echo $this->get_field_name( \'title_three\' ); ?>" type="text" value="<?php echo esc_attr( $title_three ); ?>" />
    </p>        
    <p>
        <label for="<?php echo $this->get_field_id(\'column_third\'); ?>">İçerik: 
            <select class=\'widefat\' id="<?php echo $this->get_field_id(\'column_third\'); ?>" name="<?php echo $this->get_field_name(\'column_third\'); ?>">
                <option value=\'recent\'<?php echo ($column_third==\'recent\')?\'selected\':\'\'; ?>><?php _e(\'Son Eklenen Ürünler\',\'prostore\'); ?></option>
                <option value=\'featured\'<?php echo ($column_third==\'featured\')?\'selected\':\'\'; ?>><?php _e(\'Öne Çıkan Ürünler\',\'prostore\'); ?></option>
                <option value=\'popular\'<?php echo ($column_third==\'popular\')?\'selected\':\'\'; ?>><?php _e(\'Popüler Ürünler\',\'prostore\'); ?></option> 
                <option value=\'onsale\'<?php echo ($column_third==\'onsale\')?\'selected\':\'\'; ?>><?php _e(\'İndirimli Ürünler\',\'prostore\'); ?></option> 
                <option value=\'best\'<?php echo ($column_third==\'best\')?\'selected\':\'\'; ?>><?php _e(\'Çok Satanlar\',\'prostore\'); ?></option> 
            </select>                
        </label>
    </p>        
<?php
}


/**
 * Processing widget options on save
 *
 * @param array $new_instance The new options
 * @param array $old_instance The previous options
 */
public function update( $new_instance, $old_instance ) {
    // processes widget options to be saved
    foreach( $new_instance as $key => $value )
    {
        $updated_instance[$key] = sanitize_text_field($value);
    }

    return $updated_instance;
}

/**
 * Recent Products
 *
 */ 
public function recent($title = \'\') {

    echo \'<div class="widget woocommerce widget_products">\';
    echo \'<ul class="product_list_widget">\';
    echo \'<h2 class="widgettitle">\'.$title.\'</h2>\';

    $args = array(
        \'post_type\'         =>  \'product\',
        \'status\'            =>  \'publish\',
        \'no_found_rows\'     =>  1,
        \'posts_per_page\'    =>  10,
        \'orderby\'           =>  \'date\',
        \'order\'             =>  \'DESC\'
    );

    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product;

    echo \'<li>\';
    echo \'<a href="\'.esc_url( get_permalink( $product->id ) ).\'" title="\'.esc_attr( $product->get_title() ).\'">\';
    echo $product->get_image();
    echo \'<span class="product-title">\'.$product->get_title().\'</span>\';
    echo \'</a>\';
    echo $product->get_price_html();
    echo \'</li>\';

    endwhile;
    wp_reset_query(); 
    echo \'</ul>\';
    echo \'</div>\';
}

/**
 * Featured Products
 *
 */     
public function featured($title = \'\') {

    echo \'<div class="widget woocommerce widget_products">\';
    echo \'<ul class="product_list_widget">\';
    echo \'<h2 class="widgettitle">\'.$title.\'</h2>\';

    $meta_query   = WC()->query->get_meta_query();
    $meta_query[] = array(
        \'key\'   => \'_featured\',
        \'value\' => \'yes\'
    );

    $args = array(
        \'post_type\'         =>  \'product\',
        \'status\'            =>  \'publish\',
        \'no_found_rows\'     =>  1,
        \'posts_per_page\'    =>  10,
        \'orderby\'           =>  \'date\',
        \'order\'             =>  \'DESC\',
        \'meta_query\'        =>  $meta_query
    );

    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product;

    echo \'<li>\';
    echo \'<a href="\'.esc_url( get_permalink( $product->id ) ).\'" title="\'.esc_attr( $product->get_title() ).\'">\';
    echo $product->get_image();
    echo \'<span class="product-title">\'.$product->get_title().\'</span>\';
    echo \'</a>\';
    echo $product->get_price_html();
    echo \'</li>\';

    endwhile;
    wp_reset_query(); 
    echo \'</ul>\';
    echo \'</div>\';
}

/**
 * Popular Products
 *
 */     
public function popular($title = \'\') {

    echo \'<div class="widget woocommerce widget_products">\';
    echo \'<ul class="product_list_widget">\';
    echo \'<h2 class="widgettitle">\'.$title.\'</h2>\';

    add_filter( \'posts_clauses\',  array( WC()->query, \'order_by_rating_post_clauses\' ) );

    $args = array(
        \'post_type\'         =>  \'product\',
        \'status\'            =>  \'publish\',
        \'no_found_rows\'     =>  1,
        \'posts_per_page\'    =>  10,
        \'orderby\'           =>  \'date\',
        \'order\'             =>  \'DESC\'
    );

    $args[\'meta_query\'] = WC()->query->get_meta_query();

    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product;

    echo \'<li>\';
    echo \'<a href="\'.esc_url( get_permalink( $product->id ) ).\'" title="\'.esc_attr( $product->get_title() ).\'">\';
    echo $product->get_image();
    echo \'<span class="product-title">\'.$product->get_title().\'</span>\';
    echo \'</a>\';
    echo $product->get_price_html();
    echo \'</li>\';

    endwhile;
    remove_filter( \'posts_clauses\', array( WC()->query, \'order_by_rating_post_clauses\' ) );
    wp_reset_query(); 
    echo \'</ul>\';
    echo \'</div>\';
}   

/**
 * On Sale Products
 *
 */     
public function onsale($title = \'\') {

    echo \'<div class="widget woocommerce widget_products">\';
    echo \'<ul class="product_list_widget">\';
    echo \'<h2 class="widgettitle">\'.$title.\'</h2>\';

    $args = array(
        \'posts_per_page\'    => 10,
        \'no_found_rows\'     => 1,
        \'post_status\'       => \'publish\',
        \'post_type\'         => \'product\',
        \'meta_query\'        => WC()->query->get_meta_query(),
        \'post__in\'          => array_merge( array( 0 ), wc_get_product_ids_on_sale() )
    );

    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product;

    echo \'<li>\';
    echo \'<a href="\'.esc_url( get_permalink( $product->id ) ).\'" title="\'.esc_attr( $product->get_title() ).\'">\';
    echo $product->get_image();
    echo \'<span class="product-title">\'.$product->get_title().\'</span>\';
    echo \'</a>\';
    echo $product->get_price_html();
    echo \'</li>\';

    endwhile;
    wp_reset_query(); 
    echo \'</ul>\';
    echo \'</div>\';
}

/**
 * Best Selling Products
 *
 */     
public function best($title = \'\') {

    echo \'<div class="widget woocommerce widget_products">\';
    echo \'<ul class="product_list_widget">\';
    echo \'<h2 class="widgettitle">\'.$title.\'</h2>\';

    $args = array(
        \'post_type\'         =>  \'product\',
        \'status\'            =>  \'publish\',
        \'no_found_rows\'     =>  1,
        \'posts_per_page\'    =>  10,
        \'orderby\'           =>  \'meta_value_num\',
        \'meta_key\'          =>  \'total_sales\',
        \'order\'             =>  \'DESC\'
    );

    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product;

    echo \'<li>\';
    echo \'<a href="\'.esc_url( get_permalink( $product->id ) ).\'" title="\'.esc_attr( $product->get_title() ).\'">\';
    echo $product->get_image();
    echo \'<span class="product-title">\'.$product->get_title().\'</span>\';
    echo \'</a>\';
    echo $product->get_price_html();
    echo \'</li>\';

    endwhile;
    wp_reset_query(); 
    echo \'</ul>\';
    echo \'</div>\';
}   
}

相关推荐

My widgets do not save

每次我保存我的小部件并离开页面时,我的小部件都会消失。侧边栏已完全清空,不会保存任何更改。控制台或PHP日志中没有任何错误。如果我将小部件直接复制并保存在数据库中widgets_text, 它们将被显示,但我仍然无法在侧边栏中添加或删除任何内容。这只发生在我的右侧边栏上,左侧边栏工作正常,但它们都以相同的方式注册。这是我注册侧边栏的方式:function my_widgets_init() { register_sidebar( array ( \'name\'