• Resolved Jo?o Miguel

    (@babaloo)


    Hi there,
    Is there a way I can insert a HTML slider straight into a page template?
    I got it to work with the gallery, with

    <?php
        if ( class_exists( 'BXSG_ThemeUtils' ) ) {
    		BXSG_ThemeUtils::the_post_gallery( array(
    		'exclude_featured' => 1
    		) );
    	}
    ?>

    What I want to do is
    A) Add a bit of styled html text to the gallery slides

    or

    B) Build an html slide altogether and insert it outside the entry content area.

    [slider]
        This is my first slide. I can contain any html you like.
    [next-slide]
        And the shortcode above has made this text be the second slider.
    [next-slide]
        And thus we are now having the third slide of this slider. Below we close the initial shortcode to notify the end
        of the slider. Simple, isn't it?
    [/slider]

    In the plugin code you say

    class BXSG_ThemeUtils {
    
    	/**
    	 * Outputs a gallery related to the current post. If you need to change the output, you can use the
    	 * <code>get_the_post_gallery</code> function
    	 *
    	 * @param array $params the parameters that are passed to the [gallery] or [bxgallery] shortcodes to customize
    	 * the output. Please refer to the shortcode reference to know which parameters are available.
    	 */
    	public static function the_post_gallery( $params ) {
    		echo self::get_the_post_gallery( $params );
    	}
    
    	public static function get_the_post_gallery( $params ) {
    		global $bsxg_plugin;
    		return $bsxg_plugin->gallery_shortcode->process_shortcode( $params );
    	}
    }

    Can I add HTML to the slider with this? How so?

    Thanks for the great code!

    https://www.ads-software.com/plugins/bxslider-integration/

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can always use the do_shortcode function:

    <?php
    $my_slider = '[slider]';
    $my_slider .= '<p>test 1</p>';
    $my_slider .= '[next-slide]';
    $my_slider .= '<p>test 2</p>';
    $my_slider .= '[/slider]';
    
    do_shortcode( $my_slider );
    ?>
    Thread Starter Jo?o Miguel

    (@babaloo)

    Yep, that’s right. It would be nice though to have an interface so that clients and everyday users could update/ edit the slider. Thanks for your response, anyway!

    Thread Starter Jo?o Miguel

    (@babaloo)

    So here’s a workaround to add a bit of html content to the bxslider gallery.

    This will work with images attached to any given post or page, but html content must be edited in the Media Library > Media File > Edit > Description field.
    There’s just a couple of edits to the plugin code. First, add a variable to extract the content from the attachment’s description field. Finally, insert the html markup in the concatenated string.

    bxslider-integration/includes/gallery-shortcode.view.php
    Inside the foreach loop, which iterates the gallery attachments, you will add a variable for the attachments content and the html markup to render the string.

    <div class="gallery-wrapper">
    	<div class="bxslider">
    <?php
    foreach ( $attachments as $attachment ) :
    	$img_attr = wp_get_attachment_image_src( $attachment->ID, $size );
    	$title = apply_filters( 'the_title', $attachment->post_title, $attachment->ID );
    	$desc = $attachment->post_excerpt;
    	$mytext = apply_filters ("the_content", $attachment->post_content);
    /* The $my_text variable extracts the attachment html content.
    Use the description field in the Media Library to edit the markup.*/
    ?>
      		<div class="bxslide"><!-- slide div -->
    <?php echo sprintf( '<div><img src="%1$s" alt="%2$s" title="%3$s" /></div><div id="my_content_here">%4$s</div>',
      			$img_attr[0], esc_attr( $desc ), esc_attr( $title ),$mytext );
      		?></div>
    <?php
    endforeach; ?>
    	</div>
    	</div>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘HTML slider template tag?’ is closed to new replies.