This topic has 19 replies, 2 voices, and was last updated 7 years, 10 months ago ago by Eva Kemp
Hello,
I noticed a weird behavior of owl slider concerning the “first” and “last” classes. I am using the [etheme_products] shortcode to display products by ID. My goal is to border the first slide. I was happy to find that the first slide has it’s own class addition called “first” and added the border successfully via my childtheme’s style.css:
.slide-item .first {
border: 1px solid #888 !important;
}
But the border was not only added to the first slide, but also to the 5th. And the 4th item has the class “last”.
I noticed this behavior not only on my page but also on your demo site in related products section: preview.themeforest.net/item/royal-multipurpose-wordpress-theme/full_screen_preview/8611976
This means that this has nothing to do with my childtheme or any plugins (so there is no need to give you my credentials), its Royal theme that says somewhere in it’s code that the first item gets the class “first” and every 4th item gets the class “last”, even if there are more than 4 items in the slider.
Could you please tell me what to do in order to style only the first item in the owl slider different from the other items?
Many thanks in advance and best wishes!
I think I found the part that causes the problem:
In content-product-slider.php there is this part:
// Extra post classes
$classes = '';
if ( 0 == ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] || 1 == $woocommerce_loop['columns'] )
$classes .= 'first ';
if ( 0 == $woocommerce_loop['loop'] % $woocommerce_loop['columns'] )
$classes .= 'last ';
When I edit it to the following, it seems to work but I dont know if this is a proper solution or if this will cause any problems…?
// Extra post classes
$classes = '';
if ( 0 == ( $woocommerce_loop['loop'] - 1 ) )
$classes .= 'first ';
if ( 0 == $woocommerce_loop['loop'] % $woocommerce_loop['columns'] )
$classes .= 'last ';
Ok sorry its me again,
also in content-product-slider.php there is this part that says that there should be 4 columns:
// Store column count for displaying the grid
if ( empty( $woocommerce_loop['columns'] ) )
$woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 );
What is this code for and how can I edit it in order to set the colums dynamically?
Hello,
Sorry for a delay.
That code is for Products element in VC editor. Columns option is appeared when Grid is selected http://storage5.static.itmages.com/i/17/0111/h_1484130717_9812041_813dab7a45.jpeg .
Regards,
Eva Kemp.
Thank you, but I don’t want to use grid, I want to use slider…
Hello,
From your previous message I saw you resolved the problem, didn’t you?
Regards,
Eva Kemp.
No, it’s very confusing.
If I add the shortcode [etheme_products] to a page, classes are set like this:
1. Item class FIRST
2. Item
3. Item
4. Item class LAST
5. Item class FIRST
[…]
But if I add the same shortcode on product description field of a product, the classes are set like this:
1. Item
2. Item
3. Item class LAST
4. Item class FIRST
5. Item
[…]
When I add two shortcodes like [etheme_products][etheme_products], the first slider has the classes set like my second example and the second slider has the classes set like the first example.
I really don’t get it, its totally confusing. I would like to ignore all of these confusing classes and just find a way to style the first item of the slider, but I dont know how. :first-child doesnt work here…
Hello,
You can use sliders ids, they are unique and use css code for each of them.
Also you can select how many items to show in product slider settings http://prntscr.com/dwp5un .
Regards,
Eva Kemp.
Where can I set the slider id? I dont find this option in the slider-settings…
Or do you mean that I should use the ids that are automatically generated like slider-8637?
Thats no solution as I need these sliders on every product page…
I just need to understand why this part results in these weird classes
// Store loop count we're currently on
if ( empty( $woocommerce_loop['loop'] ) )
$woocommerce_loop['loop'] = 0;
// Store column count for displaying the grid
if ( empty( $woocommerce_loop['columns'] ) )
$woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 );
// Ensure visibility
if ( ! $product || ! $product->is_visible() )
return;
// Increase loop count
$woocommerce_loop['loop']++;
// Extra post classes
$classes = '';
if ( 0 == ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] || 1 == $woocommerce_loop['columns'] )
$classes .= 'first ';
if ( 0 == $woocommerce_loop['loop'] % $woocommerce_loop['columns'] )
$classes .= 'last ';
I just want the first item in the slider to be marked with “first” or something else, thats all.
Hello,
You need do the following:
– go to framework/theme-functions.php
– find etheme_create_slider
function
– copy it to child theme without if(!function_exists('etheme_create_slider')) {
– add to it this code http://prnt.sc/dxj40b
$first_slide_class = ( $_i === 1 ) ? 'your-first-slide-class' : '';
– and you’ll receive this result http://prnt.sc/dxj4p2
Regards,
Eva Kemp.
Thank you, I did what you said, but the change has no effect, it doesnt add the class.
Here is the code that I added to my childtheme’s functions.php
function etheme_create_slider($args, $slider_args = array()){//, $title = false, $shop_link = true, $slider_type = false, $items = '[[0, 1], [479,2], [619,2], [768,4], [1200, 4], [1600, 4]]', $style = 'default'
global $wpdb, $woocommerce_loop;
$product_per_row = etheme_get_option('prodcuts_per_row');
extract(shortcode_atts(array(
'title' => false,
'shop_link' => false,
'slider_type' => false,
'items' => '[[0, 1], [479,2], [619,2], [768,4], [1200, 4], [1600, 4]]',
'style' => 'default',
'block_id' => false
), $slider_args));
$box_id = rand(1000,10000);
$multislides = new WP_Query( $args );
$shop_url = get_permalink(woocommerce_get_page_id('shop'));
$class = $container_class = $title_output = '';
if(!$slider_type) {
$woocommerce_loop['lazy-load'] = true;
$woocommerce_loop['style'] = $style;
}
if(!$slider_type) {
$container_class = '';
$class .= 'owl-carousel';
} elseif($slider_type == 'swiper') {
$container_class = 'et-swiper-container';
$class .= 'swiper-wrapper';
}
if ( $multislides->have_posts() ) :
if ($title) {
$title_output = '<h2 class="title"><span>'.$title.'</span></h2>';
}
echo '<div class="carousel-area '.$container_class.' slider-'.$box_id.'">';
echo $title_output;
echo '<div class="'.$class.' productCarousel">';
$_i=0;
if($block_id && $block_id != '' && et_get_block($block_id) != '') {
echo '<div class="slide-item '.$slider_type.'-slide">';
echo et_get_block($block_id);
echo '</div><!-- slide-item -->';
}
while ($multislides->have_posts()) : $multislides->the_post();
$_i++;
$first_slide_class = ( $_i === 1 ) ? 'your-first-slide-class' : '';
if(class_exists('Woocommerce')) {
global $product;
if (!$product->is_visible()) continue;
echo '<div class="slide-item product-slide '.$slider_type.'-slide">';
woocommerce_get_template_part( 'content', 'product-slider' );
echo '</div><!-- slide-item -->';
}
endwhile;
echo '</div><!-- products-slider -->';
echo '</div><!-- slider-container -->';
endif;
wp_reset_query();
unset($woocommerce_loop['lazy-load']);
unset($woocommerce_loop['style']);
if($items != '[[0, 1], [479,2], [619,2], [768,4], [1200, 4], [1600, 4]]') {
$items = '[[0, '.$items['phones'].'], [479,'.$items['tablet'].'], [619,'.$items['tablet'].'], [768,'.$items['tablet'].'], [1200, '.$items['notebook'].'], [1600, '.$items['desktop'].']]';
}
if(!$slider_type) {
echo '
<script type="text/javascript">
jQuery(".slider-'.$box_id.' .productCarousel").owlCarousel({
items:4,
lazyLoad : true,
navigation: true,
navigationText:false,
rewindNav: false,
itemsCustom: '.$items.'
});
</script>
';
} elseif($slider_type == 'swiper') {
echo '
<script type="text/javascript">
if(jQuery(window).width() > 767) {
jQuery(".slider-'.$box_id.'").etFullWidth();
var mySwiper'.$box_id.' = new Swiper(".slider-'.$box_id.'",{
keyboardControl: true,
centeredSlides: true,
calculateHeight : true,
slidesPerView: "auto",
mode: "horizontal"
})
} else {
var mySwiper'.$box_id.' = new Swiper(".slider-'.$box_id.'",{
calculateHeight : true
})
}
jQuery(function($){
$(".slider-'.$box_id.' .slide-item").click(function(){
mySwiper'.$box_id.'.swipeTo($(this).index());
$(".lookbook-index").removeClass("active");
$(this).addClass("active");
});
$(".slider-'.$box_id.' .slide-item a").click(function(e){
if($(this).parents(".swiper-slide-active").length < 1) {
e.preventDefault();
}
});
}, jQuery);
</script>
';
}
}
Even if I add
$first_slide_class = ( $_i === 1 ) ? 'your-first-slide-class' : '';
directly to theme-functions, it has no effect.
Hello,
Please provide FTP credentials.
Regards,
Eva Kemp.
Ok, please find them in private content. Thank you.
Hello,
It was added . Please check .
You had to do this way http://prnt.sc/dxj40b and not this http://prnt.sc/dy204b .
Regards,
Eva Kemp.
Ah ok I didnt see the second part! Thank you very much! Could you please delete the link to my testpage and the screenshot? Thank you and have a nice weekend!
Hello,
Done. You’re welcome.
Regards,
Eva Kemp.
The issue related to '‘Owl slider adds class "last" to every 4th item in slider’' has been successfully resolved, and the topic is now closed for further responses