Ultimate Post List Shortcode

Below, you’ll find a detailed guide on how to add the Ultimate Post List 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 Ultimate Post List Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Ultimate Post List Plugin and the shortcodes it provides:

Plugin Icon
Ultimate Post List

"Ultimate Post List is a versatile WordPress plugin that allows you to create, customize, and manage list of posts with ease. Ideal for bloggers and website owners who want streamlined content organization."

★★★★☆ (13) Active Installs: 3000+ Tested with: 6.2.3 PHP Version: 5.2
Included Shortcodes:
  • [UPL_SHORTCODE_NAME]

Ultimate Post List [UPL_SHORTCODE_NAME] Shortcode

The Ultimate Post List shortcode is a powerful tool for customizing your WordPress site. It allows you to generate a list of posts based on specific criteria. This shortcode fetches a list of posts based on the ‘id’, ‘list_title’, and ‘included_categories’ attributes. It ensures the list is published and sanitizes the list id for security. The list’s appearance is controlled by the ‘before_widget’, ‘after_widget’, ‘before_title’, and ‘after_title’ parameters. If user-defined attributes are present, they are sanitized and added to the list parameters. Finally, the shortcode returns the HTML of the post list.

Shortcode: [UPL_SHORTCODE_NAME]

Parameters

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

  • id – Unique identifier of the post list
  • list_title – Sets the title of the post list
  • included_categories – Categories to include in the post list

Examples and Usage

Basic example – A straightforward usage of the shortcode to display a post list by referencing its ID.

[upl id=1 /]

Advanced examples

Using the shortcode to display a post list by referencing its ID and including a custom title for the list.

[upl id=1 list_title="My Custom Title" /]

Using the shortcode to display a post list by referencing its ID and specifying the categories to include in the list.

[upl id=1 included_categories="category1, category2" /]

Combining multiple attributes in the shortcode to display a post list by referencing its ID, including a custom title, and specifying the categories to include.

[upl id=1 list_title="My Custom Title" included_categories="category1, category2" /]

PHP Function Code

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

Shortcode line:

add_shortcode( UPL_SHORTCODE_NAME, array( __CLASS__, 'upl_shortcode_handler' ) );

Shortcode PHP function:

                    function upl_shortcode_handler( $user_atts ) {
		
		// initialize shortcode attributes
		$valid_atts = array(
			'id' => 0,
			'list_title' => '',
			'included_categories' => '',
			//'excluded_categories' => '',
		);
	
		// set defaults for missing attributes
		$merged_atts = shortcode_atts( $valid_atts, $user_atts );
		
		// sanitize list id
		$list_id = absint( $merged_atts[ 'id' ] );
		
		// quit if id is 0 or list not published
		if ( ! ( $list_id and 'publish' == get_post_status( $list_id ) ) ) {
			return;
		}
		
		// get settings
		$list_settings = self::get_stored_settings( $list_id );
		
		// set params for list printer
		$args = array(
			'list_id'		=> $list_id,
			'before_widget'	=> '',
			'after_widget'	=> '',
			'before_title'	=> '<' . $list_settings[ 'list_title_element' ][ 0 ] . '>',
			'after_title'	=> '</' . $list_settings[ 'list_title_element' ][ 0 ] . '>',
		);

		// if set by user add sanitize attributes to arguments list
		foreach ( array_keys( $valid_atts ) as $key ) {
			if ( isset( $user_atts[ $key ] ) ) {
				$args = self::sanitize_shortcode_atts( $merged_atts, $args, $key );
			}
		}
		
		// print the list
		return self::get_html( $args );
		
	}
                    

Code file location:

ultimate-post-list/ultimate-post-list/includes/class-Ultimate_Post_List_Public.php

Conclusion

Now that you’ve learned how to embed the Ultimate Post List 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 *