Posts shortcode

[su_posts] shortcode is intended for display of posts, pages and random post types. You can display posts from specific category or by specific tag. You can also choose random taxonomies and select the number of displayed posts. This shortcode uses WP_Query class.

Full list of shortcode's parameters can be found under the plugin page at: Dashboard - Shortcodes - Available shortcodes - Posts.

Pagination

Unfortunately, pagination is currently not available in shortcode. This function will be added in the next versions. Plugin version at the moment of writing this: 4.9.9.

Built-in templates

[su_posts] shortcode allows to use various templates for display of posts. You can use several templates built into the plugin. Built-in templates are located in /wp-content/plugins/shortcodes-ultimate/templates/ folder. The list of built-in templates is given below:

  • default-loop.php - posts loop
  • teaser-loop.php - posts loop with thumbnails and titles
  • single-post.php - single post template
  • list-loop.php - unordered list with post titles

Use template attribute to change the template. The value of this attribute should be relative path to template file from plugin folder or folder of your theme. Shortcode example:

[su_posts template="templates/default-loop.php"]

In this example, search for the template will be made in the following locations (in specified order):

  1. /wp-content/themes/child-theme/templates/default-loop.php
  2. /wp-content/themes/parent-theme/templates/default-loop.php
  3. /wp-content/plugins/shortcodes-ultimate/templates/default-loop.php

Template editing

Do not edit templaes in plugin folder, since all your changes will be deleted at the next plugin update. To change one of built-in templates, you should copy it to the folder of your theme first. For convenience, you can copy the whole "templates" folder from plugin folder to the folder of your theme.  Folder with templates may have other name than "templates". Resulting paths to template files should look like:

/wp-content/themes/your-theme/templates/

Now you can edit imported templates. As it was mentioned above, plugin will search for template file in the theme folder first.

Creation of custom templates

You can create your own templates for [su_posts] shortcode, which makes it incredibly powerful. Your own templates should be created in the folder with your active theme. For example, you can create a folder "posts-templates" in the folder with your active theme. Create my-loop.php file in this folder and place the following code in it:

<?php
if ( $su_posts->have_posts() ) :
	while ( $su_posts->have_posts() ) :
		$su_posts->the_post();
		echo '<h2>' . get_the_title() . '</h2>';
		the_excerpt();
	endwhile;
else :
	echo 'Posts not found';
endif;

Now you can use the following shortcode to display posts with custom template:

[su_posts template="posts-templates/my-loop.php"]