4.1/5 - (7 bình chọn)

Hôm nay mình xin chia sẻ đoạn code slider brand, áp dụng cho plugin Perfect Brands for WooCommerce và dùng trên theme flatsome, theme khác thì xài không được nhé, muốn xài thì phải sửa code lại nhé.

Giờ thì copy đoạn code, bỏ vô functions.php của flatsome child đang dùng nhé.

function pmo_brands_slider()
{
    $ux_slider = '[ux_slider arrows="false" freescroll="false" bullets="false"]';
    
    $display   = false;
    $terms     = get_terms([
        'taxonomy'   => 'pwb-brand',
        'hide_empty' => false,
    ]);

    if ($terms) {
        foreach ($terms as $term) {
            $image = get_term_meta($term->term_id, 'pwb_brand_image', true);

            if ($image) {
                $display    = true;
                $ux_slider .= '[logo hover="color" img="' . $image . '" link="' . get_term_link($term) . '" image_size="original" height="50px"]';
            }
        }
    }

    $ux_slider .= '[/ux_slider]';

    if ($display) {
        echo do_shortcode($ux_slider);
    }
}
add_shortcode('brands_slider', 'pmo_brands_slider');

Sau khi thêm code vào functions.php, các bạn có thể chèn shortcode [brands_slider] vào nơi mình muốn hiển thị nhé.

Chúc các bạn thành công!

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *