Slideshow Shortcode

Below, you’ll find a detailed guide on how to add the Slideshow Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Slideshow Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Slideshow Plugin and the shortcodes it provides:

Plugin Icon
Slideshow

"Slideshow is a dynamic WordPress plugin designed to create stunning and interactive slideshows. It's a user-friendly tool that brings life to your content and enhances site aesthetics."

✩✩✩✩✩ () Active Installs: 2000+ Tested with: 3.0.5 PHP Version: false
Included Shortcodes:
  • [slideshow]

Slideshow [slideshow] Shortcode

The ‘slideshow’ shortcode is a powerful tool that displays an image slideshow from the post’s attached images. It allows you to customize the order and size of the images. It also includes navigation controls and optional captions for each image.

Shortcode: [slideshow]

Parameters

Here is a list of all possible slideshow shortcode parameters and attributes:

  • order – Defines the order of the slides, can be ‘ASC’ (ascending) or ‘DESC’ (descending).
  • orderby – Determines what parameter the slides are ordered by, default is ‘menu_order ID’.
  • id – Specifies the ID of the post to display slides from.
  • size – Sets the size of the slides, default is ‘large’.
  • include – Allows specific slides to be included, using their IDs.
  • exclude – Excludes certain slides from the slideshow, using their IDs.
  • numberposts – Determines the maximum number of slides to show, default is -1 (show all).

Examples and Usage

Basic example – A simple usage of the slideshow shortcode without any additional parameters. It will display all the images attached to the post in a slideshow format.

[slideshow /]

Advanced examples

Displaying a slideshow of images attached to a specific post by referencing the post ID. The slideshow will only include images attached to the post with the ID specified.

[slideshow id=2 /]

Displaying a slideshow with images in a specific size. The ‘size’ parameter can take any valid image size registered with WordPress, such as ‘thumbnail’, ‘medium’, ‘large’, or ‘full’.

[slideshow size='medium' /]

Excluding specific images from the slideshow. The ‘exclude’ parameter can take a comma-separated list of attachment IDs to exclude from the slideshow.

[slideshow exclude='10,15' /]

Including only specific images in the slideshow. The ‘include’ parameter can take a comma-separated list of attachment IDs to include in the slideshow.

[slideshow include='5,8' /]

Limiting the number of images in the slideshow. The ‘numberposts’ parameter can take an integer value to limit the number of images displayed in the slideshow.

[slideshow numberposts=5 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [slideshow] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'slideshow', 'slideshow_shortcode' );

Shortcode PHP function:

function slideshow_shortcode( $attr ) {
	global $post;

	/* Set up the defaults for the slideshow shortcode. */
	$defaults = array(
		'order' => 'ASC',
		'orderby' => 'menu_order ID',
		'id' => $post->ID,
		'size' => 'large',
		'include' => '',
		'exclude' => '',
		'numberposts' => -1,
	);
	$attr = shortcode_atts( $defaults, $attr );

	/* Allow users to overwrite the default args. */
	extract( apply_filters( 'slideshow_shortcode_args', $attr ) );

	/* Arguments for get_children(). */
	$children = array(
		'post_parent' => intval( $id ),
		'post_status' => 'inherit',
		'post_type' => 'attachment',
		'post_mime_type' => 'image',
		'order' => $order,
		'orderby' => $orderby,
		'exclude' => absint( $exclude ),
		'include' => absint( $include ),
		'numberposts' => intval( $numberposts ),
	);

	/* Get image attachments. If none, return. */
	$attachments = get_children( $children );

	if ( empty( $attachments ) )
		return '';

	/* If is feed, leave the default WP settings. We're only worried about on-site presentation. */
	if ( is_feed() ) {
		$output = "\n";
		foreach ( $attachments as $id => $attachment )
			$output .= wp_get_attachment_link( $id, $size, true ) . "\n";
		return $output;
	}

	$slideshow = '<div class="slideshow-set"><div class="slideshow-items">';

	$i = 0;

	foreach ( $attachments as $attachment ) {

		/* Open item. */
		$slideshow .= '<div class="slideshow-item item item-' . ++$i . '">';

		/* Get image. */
		$slideshow .= wp_get_attachment_link( $attachment->ID, $size, true, false );

		/* Check for caption. */
		if ( !empty( $attachment->post_excerpt ) )
			$caption = $attachment->post_excerpt;
		elseif ( !empty( $attachment->post_content ) )
			$caption = $attachment->post_content;
		else
			$caption = '';

		if ( !empty( $caption ) ) {
			$slideshow .= '<div class="slideshow-caption">';
			$slideshow .= '<a class="slideshow-caption-control">' . __( 'Caption', 'slideshow' ) . '</a>';
			$slideshow .= '<div class="slideshow-caption-text">' . $caption . '</div>';
			$slideshow .= '</div>';
		}

		$slideshow .= '</div>';
	}

	$slideshow .= '</div><div class="slideshow-controls">';

		$slideshow .= '<div class="slideshow-pager"></div>';
		$slideshow .= '<div class="slideshow-nav">';
			$slideshow .= '<a class="slider-prev">' . __( 'Previous', 'slideshow' ) . '</a>';
			$slideshow .= '<a class="slider-next">' . __( 'Next', 'slideshow' ) . '</a>';
		$slideshow .= '</div>';

	$slideshow .= '</div>';

	$slideshow .= '</div><!-- End slideshow. -->';

	return apply_filters( 'slideshow_shortcode', $slideshow );
}

Code file location:

slideshow/slideshow/slideshow.php

Conclusion

Now that you’ve learned how to embed the Slideshow Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *