Jump to content

Recommended Posts

Hi, this is my first post on this forum and I hope I have posted it in the right place  :P

 

I am trying to modify a custom Wordpress Shortcode that produces slides. The shortcode works pretty well, but it's a bit complicated.

So, now in the shortcode I have to use:

 slide_1="Title #1" slide_2="Title #2" slide_3="Title #3"

and so on, like in the following shortcode:

[raw]
[slides style="framed" class=""  height="300"  slide_1="Title #1" slide_2="Title #2" slide_3="Title #3"]
[slide_1]Slide 1 content...[/slide_1]
[slide_2]Slide 2 content...[/slide_2]
[slide_3]Slide 3 content...[/slide_3]
[/slides]
[/raw]

 

How should I modify the PHP code of the shortcode so I don't need to use

slide_1="Title #1" slide_2="Title #2" slide_3="Title #3"

 

The PHP code is here: http://ideone.com/lZRGS.

Please let me know if I should provide more clarification.

 

Thank you.

I have posted the PHP code here too. I really hope you can help me with this one. Thank you very much.

 

/*-----------------------------------------------------------------------------------*/
/* Slides
/*-----------------------------------------------------------------------------------*/

if( ! function_exists( 'pixy_slides' ) ) {
function pixy_slides( $id, $options ) {
	// Fixed Height
	$height = '';
	if( $options['height'] )
		$height = ' style="height:'.$options['height'].'px"';

	$output = '<ul class="pi-slides pi-slides-'.$options['setup']['style'].'">';

	// Slide content
	$i = 0;
	$class = null;
	foreach( $options['setup']['names'] as $key => $name ) {
		$output .= '<li '.$height.'>';
		switch( $options[$key]['type'] ) {
			case 'page' :
				$page_id = pixy_post_id_by_name( $options[$key]['page'], 'page' );
				$page = get_page( $page_id );
				$output .= apply_filters( 'the_content', $page->post_content );
				break;
			case 'raw' :
				$output .= apply_filters( 'the_content', stripslashes( $options[$key]['raw'] ) );
				break;
		}
		$output .= '</li>';
		$i++;
	}
	$output .= '</ul><!-- .pi-slides (end) -->';

	return $output;
}
}

if( ! function_exists( 'pixy_shortcode_slides' ) ) {
function pixy_shortcode_slides( $atts, $content = null ) {
    $default = array(
            'style' => 'framed', // framed, open, left, right
            'height' => '', // Optional fixed height for inside of tabs
		'class' => '' // Optional class for element-tabs container
    );
    extract( shortcode_atts( $default, $atts ) );
    if( isset( $atts['style'] ) ) unset( $atts['style'], $atts['class'], $atts['height'] );
    $id = uniqid( 'slides_'.rand() );
    $num = count( $atts ) - 1;
	$i = 1;
	$options = array(
    	'setup' => array(
    		'num' => $num,
    		'style' => $style,
			'class' => $class,
    		'names' => array()
    	),
    	'height' => $height
    );
    if( is_array( $atts ) && ! empty( $atts ) ) {
		foreach( $atts as $key => $slide ) {
			$options['setup']['names']['slide_'.$i] = $slide;
			$slide_content = explode( '[/'.$key.']', $content );
			$slide_content = explode( '['.$key.']', $slide_content[0] );
			$options['slide_'.$i] = array(
				'type' => 'raw',
				'raw' => $slide_content[1],
			);
			$i++;
		}
		$output = '<div class="element element-slides '.$class.' '.pixy_get_classes( 'element_slides', true ).'">'.pixy_slides( $id, $options ).'</div><!-- .element (end) -->';
	} else {
		$output = '<p class="pi-warning alert">'.__( 'No slides found', 'aeryn' ).'</p>';
	}
    return $output;
}
}
add_shortcode( 'slides', 'pixy_shortcode_slides' );

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.