Bogh Posted June 7, 2012 Share Posted June 7, 2012 Hi, this is my first post on this forum and I hope I have posted it in the right place 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. Quote Link to comment https://forums.phpfreaks.com/topic/263801-wordpress-slideshow-shortcode-php-modification/ Share on other sites More sharing options...
Bogh Posted June 7, 2012 Author Share Posted June 7, 2012 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' ); Quote Link to comment https://forums.phpfreaks.com/topic/263801-wordpress-slideshow-shortcode-php-modification/#findComment-1351870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.