Extend Shortcodes Ultimate Plugin - Template php question

Hello,
I'm driving myself nuts with lack of php knowledge today! I'm using the shortcodes ultimate plugin and basically am trying to utilize 2 shortcodes together. The plugin offers templates for its list shortcode and that is what I'm editing.

Ultimately what I need to accomplish here is display a list of posts by category where each post is contained within a spoiler - Post title in the spoiler title area and post excerpt displaying once the spoiler is expanded.

To do this I've been trying to alter the post list shortcode template and add the spoiler shortcode to it so the post title, meta, comments count shows up in the spoiler title area and the post excerpt displays when the spoiler is expanded.

This really should be basic php but I dont think I'm getting it right.

Here is the template:

<div class="su-posts su-posts-default-loop">
	<?php
		// Posts are found
		if ( $posts->have_posts() ) {
			while ( $posts->have_posts() ) :
				$posts->the_post();
				global $post;
				?>

				<div id="su-post-<?php the_ID(); ?>" class="su-post">
					<?php if ( has_post_thumbnail() ) : ?>
						<a class="su-post-thumbnail" href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
					<?php endif; ?>
					<h2 class="su-post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
					<div class="su-post-meta"><?php _e( 'Posted', 'shortcodes-ultimate' ); ?>: <?php the_time( get_option( 'date_format' ) ); ?></div>
					<div class="su-post-excerpt">
						<?php the_excerpt(); ?>
					</div>
					<a href="<?php comments_link(); ?>" class="su-post-comments-link"><?php comments_number( __( '0 comments', 'shortcodes-ultimate' ), __( '1 comment', 'shortcodes-ultimate' ), '% comments' ); ?></a>
				</div>

				<?php
			endwhile;
		}
		// Posts not found
		else {
			echo '<h4>' . __( 'Posts not found', 'shortcodes-ultimate' ) . '</h4>';
		}
	?>
</div>

Here is the shortcode I'm working to add to this template, it has an opening and a closing section to it:
echo do_shortcode( '[su_spoiler title="POST TITLE / META GOES HERE"] EXCERPT GOES HERE [/su_button]' );

The shortcodes ultimate wiki also offers this:

echo Su_Shortcodes::spoiler(
	// First argument is array with shortcode attributes
	array(
		'style' => 'default',

	),
	// Second argument is a shortcode content (between opening and closing tags)
	'Click me'
);

// Equal to [su_button style="flat" background="#0099ff"] Click me [/su_button]

Shortcodes ultimate documentation on this: http://gndev.info/kb/use-shortcodes-template-files-another-plugins/

Here is the code from the plugin that show everything we have to work with in the spoiler functionality:

// spoiler
				'spoiler' => array(
					'name' => __( 'Spoiler', 'su' ),
					'type' => 'wrap',
					'group' => 'box',
					'atts' => array(
						'title' => array(
							'default' => __( 'Spoiler title', 'su' ),
							'name' => __( 'Title', 'su' ), 'desc' => __( 'Text in spoiler title', 'su' )
						),
						'open' => array(
							'type' => 'bool',
							'default' => 'no',
							'name' => __( 'Open', 'su' ),
							'desc' => __( 'Is spoiler content visible by default', 'su' )
						),
						'style' => array(
							'type' => 'select',
							'values' => array(
								'default' => __( 'Default', 'su' ),
								'fancy' => __( 'Fancy', 'su' ),
								'simple' => __( 'Simple', 'su' )
							),
							'default' => 'default',
							'name' => __( 'Style', 'su' ),
							'desc' => __( 'Choose style for this spoiler', 'su' ) . '%su_skins_link%'
						),
						'icon' => array(
							'type' => 'select',
							'values' => array(
								'plus'           => __( 'Plus', 'su' ),
								'plus-circle'    => __( 'Plus circle', 'su' ),
								'plus-square-1'  => __( 'Plus square 1', 'su' ),
								'plus-square-2'  => __( 'Plus square 2', 'su' ),
								'arrow'          => __( 'Arrow', 'su' ),
								'arrow-circle-1' => __( 'Arrow circle 1', 'su' ),
								'arrow-circle-2' => __( 'Arrow circle 2', 'su' ),
								'chevron'        => __( 'Chevron', 'su' ),
								'chevron-circle' => __( 'Chevron circle', 'su' ),
								'caret'          => __( 'Caret', 'su' ),
								'caret-square'   => __( 'Caret square', 'su' ),
								'folder-1'       => __( 'Folder 1', 'su' ),
								'folder-2'       => __( 'Folder 2', 'su' )
							),
							'default' => 'plus',
							'name' => __( 'Icon', 'su' ),
							'desc' => __( 'Icons for spoiler', 'su' )
						),
						'anchor' => array(
							'default' => '',
							'name' => __( 'Anchor', 'su' ),
							'desc' => __( 'You can use unique anchor for this spoiler to access it with hash in page url. For example: type here <b%value>Hello</b> and then use url like http://example.com/page-url#Hello. This spoiler will be open and scrolled in', 'su' )
						),
						'class' => array(
							'default' => '',
							'name' => __( 'Class', 'su' ),
							'desc' => __( 'Extra CSS class', 'su' )
						)
					),
					'content' => __( 'Hidden content', 'su' ),
					'desc' => __( 'Spoiler with hidden content', 'su' ),
					'note' => __( 'Did you know that you can wrap multiple spoilers with [accordion] shortcode to create accordion effect?', 'su' ),
					'example' => 'spoilers',
					'icon' => 'list-ul'
				),

//I'm including the below because accordions are closely related and ultimately I'm wrapping the spoilers in an accordion.

			// accordion
				'accordion' => array(
					'name' => __( 'Accordion', 'su' ),
					'type' => 'wrap',
					'group' => 'box',
					'atts' => array(
						'class' => array(
							'default' => '',
							'name' => __( 'Class', 'su' ),
							'desc' => __( 'Extra CSS class', 'su' )
						)
					),
					'content' => __( "[%prefix_spoiler]Content[/%prefix_spoiler]\n[%prefix_spoiler]Content[/%prefix_spoiler]\n[%prefix_spoiler]Content[/%prefix_spoiler]", 'su' ),
					'desc' => __( 'Accordion with spoilers', 'su' ),
					'note' => __( 'Did you know that you can wrap multiple spoilers with [accordion] shortcode to create accordion effect?', 'su' ),
					'example' => 'spoilers',
					'icon' => 'list'
				),

Help would be greatly appreciated!

Thanks

  • Ian

    I cant get anything from the developers...
    Here is the static function for both spoilers and accordions:
    `public static function spoiler( $atts = null, $content = null ) {
    $atts = shortcode_atts( array(
    'title' => __( 'Spoiler title', 'shortcodes-ultimate' ),
    'open' => 'no',
    'style' => 'default',
    'icon' => 'plus',
    'anchor' => '',
    'class' => ''
    ), $atts, 'spoiler' );
    $atts['style'] = str_replace( array( '1', '2' ), array( 'default', 'fancy' ), $atts['style'] );
    $atts['anchor'] = ( $atts['anchor'] ) ? ' data-anchor="' . str_replace( array( ' ', '#' ), '', sanitize_text_field( $atts['anchor'] ) ) . '"' : '';
    if ( $atts['open'] !== 'yes' ) $atts['class'] .= ' su-spoiler-closed';
    su_query_asset( 'css', 'font-awesome' );
    su_query_asset( 'css', 'su-box-shortcodes' );
    su_query_asset( 'js', 'jquery' );
    su_query_asset( 'js', 'su-other-shortcodes' );
    do_action( 'su/shortcode/spoiler', $atts );
    return '<div class="su-spoiler su-spoiler-style-' . $atts['style'] . ' su-spoiler-icon-' . $atts['icon'] . su_ecssc( $atts ) . '"' . $atts['anchor'] . '><div class="su-spoiler-title"><span class="su-spoiler-icon"></span>' . su_scattr( $atts['title'] ) . '</div><div class="su-spoiler-content su-clearfix" style="display:none">' . su_do_shortcode( $content, 's' ) . '</div></div>';
    }

    public static function accordion( $atts = null, $content = null ) {
    $atts = shortcode_atts( array( 'class' => '' ), $atts, 'accordion' );
    do_action( 'su/shortcode/accordion', $atts );
    return '<div class="su-accordion' . su_ecssc( $atts ) . '">' . do_shortcode( $content ) . '</div>';
    }

  • Ash

    Hello @Ian

    I hope you are well today.

    Would you please try the following code?

    <div class="su-posts su-posts-default-loop">
    	<?php
    		// Posts are found
    		if ( $posts->have_posts() ) {
    			while ( $posts->have_posts() ) :
    				$posts->the_post();
    				global $post;
    				?>
    
    				<div id="su-post-<?php the_ID(); ?>" class="su-post">
                                            <?php
                                                echo do_shortcode( '[su_spoiler title="' . get_the_title() . '"]'. get_the_excerpt() .'[/su_button]' );
                                            ?>
    				</div>
    
    				<?php
    			endwhile;
    		}
    		// Posts not found
    		else {
    			echo '<h4>' . __( 'Posts not found', 'shortcodes-ultimate' ) . '</h4>';
    		}
    	?>
    </div>

    Please let me know if it works.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.