Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在电子商务中填充自定义排序/排序_Php_Html_Sorting_Post_Woocommerce - Fatal编程技术网

Php 在电子商务中填充自定义排序/排序

Php 在电子商务中填充自定义排序/排序,php,html,sorting,post,woocommerce,Php,Html,Sorting,Post,Woocommerce,我试图弄清楚如何在自定义模板页面中填充自定义顺序 这是我正在进行的工作。到目前为止,输出显示一个带有空值的选择框。当我检查视图源时,我看到了这个错误 警告:在第23行的C:\Users\Noel\Desktop\xampp\htdocs\lumiere\wp content\themes\klasik\lumiere-products-page.php中为foreach提供的参数无效 为foreach提供的无效参数是一个错误,当您试图在有问题的第23行中使用is_array将非数组的变量读取为A

我试图弄清楚如何在自定义模板页面中填充自定义顺序

这是我正在进行的工作。到目前为止,输出显示一个带有空值的选择框。当我检查视图源时,我看到了这个错误


警告:在第23行的C:\Users\Noel\Desktop\xampp\htdocs\lumiere\wp content\themes\klasik\lumiere-products-page.php中为foreach提供的参数无效


为foreach提供的无效参数是一个错误,当您试图在有问题的第23行中使用is_array将非数组的变量读取为ArrayArray时会出现此错误。然后检查$catalog\u orderby\u options是否为数组在尝试迭代之前,您甚至没有创建$catalog\u orderby\u options
<?php
    $args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'product_cat' => 'Lumiere', 'orderby' => 'rand' );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>


    <?php //Woocommerce Custom Ordering ?>
    <form class="woocommerce-ordering" method="get">
        <select name="orderby" class="orderby">
        <?php foreach ( $catalog_orderby_options as $id => $name ) : ?>
             <option value="<?php echo esc_attr( $id ); ?>" <?php selected( $orderby, $id ); ?>><?php echo esc_html( $name ); ?></option>
        <?php endforeach; ?>
        </select>

       <?php
        // Keep query string vars intact
        foreach ( $_GET as $key => $val ) {
        if ( 'orderby' === $key || 'submit' === $key ) {
            continue;
        }
        if ( is_array( $val ) ) {
            foreach( $val as $innerVal ) {
                echo '<input type="hidden" name="' . esc_attr( $key ) . '[]" value="' . esc_attr( $innerVal ) . '" />';
            }
        } else {
            echo '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $val ) . '" />';
             }
        }
        ?>
    </form>


            <li class="product product-items ">    

                    <div class="product-item">

                    <?php woocommerce_show_product_sale_flash( $post, $product ); ?>

                    <div class="product-thumbnail">
                    <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" />'; ?>
                    </div>

                    <div class="product-info">
                        <h3>
                            <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"><?php the_title(); ?></a>
                        </h3>


                        <h4 class="product-category-title">
                        <?php
                             $size = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
                             echo $product->get_categories( ', ', '<span class="posted_in">' . ' ', '.</span>' );
                        ?>
                        </h4>

                        <?php echo $product->get_sku(); ?>
                        <?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ) ?>


                        <?php if ( $price_html = $product->get_price_html() ) : ?>
                            <span class="price"><?php echo $price_html; ?></span>
                        <?php endif; ?>  


                    <div class="product-rating">
                        <?php if ($average = $product->get_average_rating()) : ?>
                            <?php echo '<div class="star-rating" title="'.sprintf(__( 'Rated %s out of 5', 'woocommerce' ), $average).'"><span style="width:'.( ( $average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' ).'</span></div>'; ?>
                        <?php endif; ?>
                    </div>

                    <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>

                    </div>

                </div>



            </li>

    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
</ul><!--/.products-->