Show Sidebar Log in
Commons In A Box Logo
  • Home
  • About
    • Project Team
    • Logos and Graphics
  • Showcase
    • CBOX Classic Showcase
    • CBOX OpenLab Showcase
  • Demo
  • Get Started
  • Documentation
    • Technical Guide
    • CBOX Classic Guide
    • CBOX OpenLab Guide
  • Support Forums
    • CBOX Classic
    • CBOX OpenLab
    • Developers Forum
  • News

Group Admins

  • Profile picture of Scott Voth

CBOX Classic Support

Public Group active 4 months ago

This group provides support for Commons In A Box Classic, our original software for community-building. Register for an account or log in to commonsinabox.org, then join the group and post your question here.

How to insert the slider by a shortcode?

Tagged: meta-slider, shortcode, slider

  • This topic has 8 replies, 3 voices, and was last updated 10 years, 6 months ago by Christian Wach.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • October 24, 2014 at 11:24 am #5217
    Iurie Malai
    Participant

    I try to insert the slider by a shortcode, but without success. Here is my function code, but something is wrong (see the result):

    add_shortcode(‘display_flex_slider’, ‘display_flex_slider_shortcode_handler’);

    function display_flex_slider_shortcode_handler(){
    $slider = infinity_option_get( ‘cbox_flex_slider’ ) > 0;
    if ( $slider === true ) {
    $flex_slider = ‘<div id=”flex-slider-wrap-full” class=”column ten”>’ . infinity_load_template( ‘engine/includes/feature-slider/template.php’ ) . ‘</div>’;
    return $flex_slider;
    }
    }

    The adapted slider code is from the Homepage Template.
    Can someone help me?

    October 25, 2014 at 10:33 am #5218
    Scott Voth
    Keymaster

    Hi Iurie @iurie –

    I’m not sure about the coding – maybe someone else on this forum can help you out with it – but instead of going through all the trouble of doing this, you might consider installing the “Meta-Slider” plugin which is very easy to use, generates its own shortcode, and lets you create 4 different types of sliders that are responsive (work well on mobile devices).  It has a lot of configurations as well.  It has a nice video tutorial to get you started.

    http://cbox107.svoth.com/wp-admin/admin.php?page=metaslider

     

    • This reply was modified 10 years, 6 months ago by Scott Voth.
    • This reply was modified 10 years, 6 months ago by Scott Voth.
    October 25, 2014 at 2:44 pm #5222
    Iurie Malai
    Participant

    @scottvoth – Scott, thank you! If I will fail with the shortcode I will try the plugin that you recommend.

    I copied the featured slider template to the template folder of my CBOX child theme and renamed it to featured-slider.php. I load it with the below shortcode/function (see the source). Also was needed a little css code: .flexslider li { display: initial !important; }. The function and the shortcode works, but somehow strange, all slides are displayed as one (all together). Is there a way to improve this behavior? I hope @haystack or @r-a-y can help.

    function display_flex_slider_shortcode_handler( $attr ){
    ob_start();
    get_template_part( ‘templates/featured’, ‘slider’ );
    return ob_get_clean();
    }

    add_shortcode(‘display_flex_slider’, ‘display_flex_slider_shortcode_handler’);

     

    October 27, 2014 at 10:32 am #5226
    Christian Wach
    Participant

    @iurie The slider is only set to load on the homepage, so you have to explicitly load it elsewhere. It’s also a bit confusing because the script now seems to be called bxSlider and I’m not sure exactly how it differs from flexSlider. However, the following code works for me:

    
    // handle shortcode during page render
    add_shortcode( 'display_flex_slider', 'display_flex_slider_shortcode_handler' );
    function display_flex_slider_shortcode_handler( $attr ) {
    	// I don't seem to need the output buffering
    	get_template_part( 'templates/featured', 'slider' );
    }
    
    // handle presence of shortcode prior to page being rendered
    add_action( 'wp', 'my_cbox_has_shortcode' );
    function my_cbox_has_shortcode() {
    	if ( is_page() ) {
    		global $post;
    		if ( has_shortcode( $post->post_content, 'display_flex_slider' ) ) {
    			add_action( 'wp_enqueue_scripts', 'my_cbox_enqueue_styles' );
    			add_action( 'close_body', 'my_cbox_theme_flex_slider_script' );
    		}
    	}
    }
    
    function my_cbox_enqueue_styles() {
    	// bxslider CSS
    	wp_enqueue_style( 
    		'my_bx_slider_css',
    		get_template_directory_uri() . '/assets/css/bxslider/jquery.bxslider.css',
    		null, // dependencies
    		0.1, // version
    		'all' // media
    	);
    	// bxslider JS
    	wp_enqueue_script( 
    		'my_bx_slider_js',
    		get_template_directory_uri() . '/assets/js/jquery.bxslider.min.js',
    		array( 'jquery' )
    	);
    }
    
    function my_cbox_theme_flex_slider_script() {
    	// render script tag 
    	?>
    	<script type="text/javascript">
    		jQuery(document).ready(function(){
    			jQuery('.slides').bxSlider({
    				adaptiveHeight: true,
    				auto: true,
    				autoHover: true,
    				mode: 'fade',
    				video: true,
    				useCSS: false,
    				controls: false,
    				pause : <?php echo infinity_option_get( 'cbox_flex_slider_time' ); ?>000,
    				speed: <?php echo infinity_option_get( 'cbox_flex_slider_transition' ); ?>
    			});
    		});
    	</script>
    	<?php
    }
    

    You’ll have to deal with any CSS inconsistencies from there, since the page width may be wider than the slider.

    Let me know if that works for you – your site seems unavailable from here.

    Cheers, Christian

    • This reply was modified 10 years, 6 months ago by Christian Wach. Reason: tweaked code
    • This reply was modified 10 years, 6 months ago by Christian Wach. Reason: added CSS advice
    October 27, 2014 at 12:33 pm #5231
    Iurie Malai
    Participant

    @haystack –
    Christian, I am impressed by your work! Thank you! I thought that the task will be a little easier :-)!

    I re-enabled my site, so you can see how your code works. It seems like it needs some adjustments.

    A small explanation: In my slider I have two test slides with two featured images – with sizes 424 × 283 and 960 × 639 px.

     

    UPDATE

    About adjustments – they are necessary in your code or I can do this by some CSS?

    • This reply was modified 10 years, 6 months ago by Iurie Malai.
    • This reply was modified 10 years, 6 months ago by Iurie Malai.
    • This reply was modified 10 years, 6 months ago by Iurie Malai.
    • This reply was modified 10 years, 6 months ago by Iurie Malai.
    October 27, 2014 at 12:41 pm #5235
    Christian Wach
    Participant

    @iurie – yes, it won’t have come through in the email notification, but I updated my reply above to say “You’ll have to deal with any CSS inconsistencies from there, since the page width may be wider than the slider.”

    My advice would be to stick to Feature Images that are wide enough to cover all likely page widths and to stick to a consistent aspect ratio as well. If you don’t have images that are wide enough, you can wrap you slider in a div to restrict its width. For example:

    <div style="width:640px;">
    [display_flex_slider]
    </div>
    

    Cheers, Christian

    October 27, 2014 at 12:44 pm #5237
    Iurie Malai
    Participant

    @haystack –
    Thanks, I will try now.

    October 27, 2014 at 2:01 pm #5239
    Iurie Malai
    Participant

    @haystack –
    Christian, I want to say a big thank you!

    The only needed adjustments was the CSS .flex-container {width: 640px; margin: 0px auto;}.
    For those who will want to implement this solution the rule is simple: all representative images for Featured Slider must have a width not less than that fixed by this CSS.

    Best regards,
    Iurie

    October 27, 2014 at 5:38 pm #5245
    Christian Wach
    Participant

    @iurie, that’s a neater solution to the width issue than mine. Glad the slider’s working for you now.

    As you say in another thread, it would be useful to have some kind of “resolved” flag for topics – like this one – that offer solutions to certain CBOX issues. Alternatively, perhaps there could be a page in the Documentation section that points to such topics.

    Cheers, Christian

  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
Log In
Group logo of CBOX Classic Support
  • Home
  • Forum
  • Announcements
  • Docs
  • Members 287
  • Send Invites

Groups

Newest | Active | Popular | Alphabetical
  • Group logo of CBOX Classic Support
    CBOX Classic Support
    287 members
  • Group logo of CBOX Pioneers
    CBOX Pioneers
    71 members
  • Group logo of CBOX Developers
    CBOX Developers
    40 members
  • Group logo of CBOX OpenLab Support
    CBOX OpenLab Support
    22 members
  • Group logo of CBOX-OL Testing Partners
    CBOX-OL Testing Partners
    12 members

CBOX has its roots in the CUNY Academic Commons, which in turn was made possible through funding from The City University of New York itself.

CUNY Logo

CUNY Academic Commons Logo

City Tech logo

The Commons In A Box was made possible through the generous support of the Alfred P. Sloan Foundation.

Alfred P. Sloan Foundation Logo

NEH Logo

The CUNY Graduate Center has directly contributed to the CUNY Academic Commons, housing the project since its inception, and has contributed to CBOX through its GC Digital Initiatives.

CUNY Graduate Center Logo

CUNY Graduate Center Digital Initiatives Logo

Powered by Commons In A Box
css.php
Skip to toolbar
  • About WordPress
    • WordPress.org
    • Documentation
    • Learn WordPress
    • Support
    • Feedback
  • Log In
  • Register