0

我正在一个 Wordpress 网站上工作,该网站有一个用于订购产品的下拉/选择列表。

我真的很想很好地设计这个样式,并且找到了一套非常好的样式,由我想使用的 codrops 提供。

然而,用于此的 HTML 使用 UL LI 列表而不是标准选择。

我需要尝试转换以下代码:

<select name="orderby" class="orderby">
    <?php
        $catalog_orderby = apply_filters( 'woocommerce_catalog_orderby', array(
            'menu_order' => __( 'Default sorting', 'woocommerce' ),

        'popularity' => __( 'Sort by popularity', 'woocommerce' ),

        'rating'     => __( 'Sort by average rating', 'woocommerce' ),

        'date'       => __( 'Sort by newness', 'woocommerce' ),

        'price'      => __( 'Sort by price: low to high', 'woocommerce' ),

        'price-desc' => __( 'Sort by price: high to low', 'woocommerce' )
    ) );

    if ( get_option( 'woocommerce_enable_review_rating' ) == 'no' )
        unset( $catalog_orderby['rating'] );

    foreach ( $catalog_orderby as $id => $name )
        echo '<option value="' . esc_attr( $id ) . '" ' . selected( $orderby, $id, false ) . '>' . esc_attr( $name ) . '</option>';
?>

变成类似这样的东西:

<div class="wrapper-dropdown">
    <span>I'm kinda the label!</span>
    <ul class="dropdown">
        <li>I'm hidden!</li>
        <li>Me too!</li>
        <li>So do I.</li>
    </ul>
</div>
4

1 回答 1

2
<div class="wrapper-dropdown">
    <span>I'm kinda the label!</span>
    <ul class="dropdown">
    <?php
        $catalog_orderby = apply_filters( 'woocommerce_catalog_orderby', array(
            'menu_order' => __( 'Default sorting', 'woocommerce' ),

        'popularity' => __( 'Sort by popularity', 'woocommerce' ),

        'rating'     => __( 'Sort by average rating', 'woocommerce' ),

        'date'       => __( 'Sort by newness', 'woocommerce' ),

        'price'      => __( 'Sort by price: low to high', 'woocommerce' ),

        'price-desc' => __( 'Sort by price: high to low', 'woocommerce' )
    ) );

    if ( get_option( 'woocommerce_enable_review_rating' ) == 'no' )
        unset( $catalog_orderby['rating'] );

    foreach ( $catalog_orderby as $id => $name )
        echo '<li>' . esc_attr( $name ) . '</li>';
?>

    </ul>
</div>

只需<option>使用回显代码切换回显<li>代码

于 2013-08-09T17:33:21.423 回答