我有这个代码到“functions.php”,用于排序和每页下拉列表的产品:
// to change sort by text
add_filter( 'woocommerce_catalog_orderby', 'wc_customize_product_sorting' );
function wc_customize_product_sorting( $sorting_options ) {
$sorting_options = array(
'menu_order' => __( 'Ταξινόμηση', 'woocommerce' ),
'popularity' => __( 'ταξινόμηση ανά πιο δημοφιλή', 'woocommerce' ),
'rating' => __( 'Sort by average rating', 'woocommerce' ),
'date' => __( 'ταξινόμηση ανά πιο πρόσφατα', 'woocommerce' ),
'price' => __( 'ταξινόμηση ανά τιμή αύξουσα', 'woocommerce' ),
'price-desc' => __( 'ταξινόμηση ανά τιμή φθήνουσα', 'woocommerce' ),
);
return $sorting_options;
}
// add a products per-page select dropdown to archive - above shop productloop
add_action( 'woocommerce_before_shop_loop', 'pro_selectbox', 25 );
function pro_selectbox() {
$per_page = filter_input( INPUT_GET, 'perpage', FILTER_SANITIZE_NUMBER_INT );
echo '<div style="float:left;" class="woocommerce-perpage">';
echo '<select onchange="if (this.value) window.location.href=this.value">';
$orderby_options = array(
'9' => '8',
'12' => '16',
'24' => '24',
'300' => 'All'
);
foreach ( $orderby_options as $value => $label ) {
echo "<option " . selected( $per_page, $value ) . " value='?perpage=$value'>$label</option>";
}
echo '</select>';
echo '</div>';
}
add_action( 'pre_get_posts', 'pro_pre_get_products_query' );
function pro_pre_get_products_query( $query ) {
$per_page = filter_input( INPUT_GET, 'perpage', FILTER_SANITIZE_NUMBER_INT );
if ( $query->is_main_query() && !is_admin() && is_post_type_archive( 'product' ) ) {
$query->set( 'posts_per_page', $per_page );
}
}
但我的问题是“每页产品”下拉列表位于“排序依据”下拉列表的下方。我想要它在它旁边。下面的示例图像。