Home › Forums › Pro Support › Change arrows, dots and autoplay settings in specific wpsp list
- This topic has 7 replies, 2 voices, and was last updated 2 years, 9 months ago by
elvin.
-
AuthorPosts
-
December 12, 2020 at 1:15 am #24156
Georgios
ParticipantDear Great Support Team of WPSP, GP and GB,
Is there any way to set different settings regarding the display of arrows, dots (hidden or not) and autoplay (like speed etc), in different wpsp lists in my website. For instance, I want to have one wpsp list with “card carousel” format with arrows only and no-autoplay and another one with “card carousel” format with dots only and autoplay.
For now I have used the below code snippet for setting the autoplay:
add_filter( ‘wpsp_carousel_args’, function( $args ) {
$args[‘autoplay’] = true;
$args[‘autoplaySpeed’] = 3000;
return $args;
} );and the below code snippet for disabling arrows:
add_filter( ‘wpsp_carousel_args’, function( $args ) {
$args[‘arrows’] = false;
return $args;
} );But the above snippets effect all my lists in my website page (I want only to specific, maybe with an ID or sth else).
Thanks in advance for your help,
Best regards
Georgios
December 13, 2020 at 7:12 pm #24195elvin
ModeratorHi,
You can modify your code to add conditions.
Example:
add_filter( 'wpsp_carousel_args', function( $args, $settings ) { if ( 123 === (int) $settings['list_id'] ) { $args['autoplay'] = true; $args['autoplaySpeed'] = 3000; } return $args; } );
And this:
add_filter( 'wpsp_carousel_args', function( $args, $settings ) { if ( 123 === (int) $settings['list_id'] ) { $args['arrows'] = false; } return $args; } );
You then replace
123
to your WPSP list id.December 13, 2020 at 11:59 pm #24201Georgios
ParticipantHello Elvin,
Thanks for your response!
I entered the snippet you provided for disabling arrows (replacing 123 with 399 which is my id for wpsp list):
add_filter( 'wpsp_carousel_args', function( $args, $settings ) { if ( 399 === (int) $settings['list_id'] ) { $args['arrows'] = false; } return $args; } );
I am using child theme of GPP, and I entered the above code at the functions.php (of the GP child theme). However, an error is returned, which is dercribed below:
Your PHP code changes were rolled back due to an error on line 28 of file wp-content/themes/generatepress-child/functions.php. Please fix and try saving again.
Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in wp-includes/class-wp-hook.php on line 289 and exactly 2 expected in wp-content/themes/generatepress-child/functions.php:28
Stack trace:
#0 wp-includes/class-wp-hook.php(289): {closure}()
#1 wp-includes/plugin.php(212): WP_Hook->apply_filters()
#2 wp-content/plugins/wp-show-posts-pro/modules/carousel/carousel.php(104): apply_filters()
#3 wp-includes/class-wp-hook.php(287): wpsp_pro_enqueue_carousel()
#4 wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters()
#5 /var/wwwand the whole page where the wpsp list exists, breaks!
Furthermore, I tried to inject the above code using the “Code Snippets” plugin, but the result was the same again.
Is there sth that I am doing wrong?
Thanks again in advance for your help!
Best regards,
Georgios
December 14, 2020 at 5:48 am #24205elvin
ModeratorAh right my bad.
Try this instead. (removed $settings as
wpsp_carousel_args()
only accepts $args)add_filter( 'wpsp_carousel_args', function( $args ) { if ( 399 === (int) $settings['list_id'] ) { $args['arrows'] = false; } return $args; } );
Let us know.
December 14, 2020 at 2:05 pm #24225Georgios
ParticipantHi Elvin,
Unfortunately, nothing happened even with the updated version of code you provided me (without
$settings
as argument at the functionwpsp_carousel_args()
).The only good thing is that now, there is no any error message at the editor.
Any other idea of how this can be achieved?
Regards,
Georgios
December 14, 2020 at 4:47 pm #24232elvin
ModeratorTry this:
add_filter( 'wpsp_carousel_args', function( $args , $settings ) { if ( 399 === (int) $settings['list_id'] ) { $args['arrows'] = 'false'; } return $args; }, 10, 2 );
Changes: I’ve added in back the
$settings
and fixed the filter args to indicate to the filter how many args its supposed to take (2).I’ve also changed
false
to'false'
so the JS library it uses (slick) reads it as a text literal string false as not making it a string will imply its a variable or a function.This should work now. I’ve made sure I tested this as opposed to the previous ones. (my bad, WordPress 5.6 had us testing things)
Let us know. 🙂
December 14, 2020 at 11:07 pm #24244Georgios
ParticipantAwesome! Now everything works fine!
Thank you very much Elvin for the support and the detailed description of the modifications!
Best regards,
Georgios
December 14, 2020 at 11:24 pm #24246elvin
ModeratorThank you very much Elvin for the support and the detailed description of the modifications!
No problem. Always glad to impart some knowledge and be of any help. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.