W4 Post List Shortcodes

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

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

Plugin Icon
W4 Post List

"W4 Post List is a versatile WordPress plugin that allows users to create and customize lists of posts, pages, or custom post types. It enhances content organization and website navigation."

★★★★☆ (92) Active Installs: 5000+ Tested with: 6.3.2 PHP Version: 5.7
Included Shortcodes:
  • [w4pl_time]
  • [w4pl_date]
  • [postlist]

W4 Post List [w4pl_time] Shortcode

The W4 Post List shortcode ‘w4pl_time’ adjusts the current time. It accepts two parameters: ‘hour’ and ‘day’. By defining ‘hour’ and ‘day’, you can manipulate the current timestamp. For instance, if you set ‘hour’ to ‘2’ and ‘day’ to ‘1’, the shortcode will return the time 26 hours from now. This is useful for scheduling posts or events.

Shortcode: [w4pl_time]

Parameters

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

  • hour – Defines the hours to add to the current time.
  • day – Specifies the days to add to the current time.

Examples and Usage

Basic example – A simple usage of the ‘w4pl_time’ shortcode with default parameters.

[w4pl_time /]

Advanced examples

Adjust the time by adding 3 hours using the ‘w4pl_time’ shortcode.

[w4pl_time hour="3" /]

Adjust the time by adding 2 days using the ‘w4pl_time’ shortcode.

[w4pl_time day="2" /]

Combine parameters to adjust the time by adding 2 days and 3 hours using the ‘w4pl_time’ shortcode.

[w4pl_time hour="3" day="2" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'w4pl_time', array( $this, 'time_shortcode' ) );

Shortcode PHP function:

function time_shortcode( $atts ) {
		$args = shortcode_atts(
			array(
				'hour' => '0',
				'day'  => '0',
			),
			$atts
		);

		$adjust = intval( $args['hour'] ) * HOUR_IN_SECONDS + intval( $args['day'] ) * DAY_IN_SECONDS;
		return time() + $adjust;
	}

Code file location:

w4-post-list/w4-post-list/includes/shortcodes/class-date-shortcode.php

W4 Post List [w4pl_date] Shortcode

The W4 Post List shortcode ‘w4pl_date’ is a versatile tool that allows you to adjust and display date and time. It accepts parameters for hour and day adjustments and a format for the final output. It uses PHP’s gmdate function to return a formatted date/time string. The ‘hour’ and ‘day’ parameters can be used to adjust the current time. The ‘format’ parameter allows custom date/time formatting.

Shortcode: [w4pl_date]

Parameters

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

  • hour – Defines the number of hours to add to the current time.
  • day – Specifies the number of days to add to the current time.
  • format – Sets the display format for the date and time.

Examples and Usage

Basic example – A basic usage of the shortcode to display the current date and time.

[w4pl_date /]

Advanced examples

Example 1 – Displaying the date and time 3 hours from now. The ‘hour’ parameter is set to ‘3’.

[w4pl_date hour="3" /]

Example 2 – Displaying the date 2 days from now. The ‘day’ parameter is set to ‘2’.

[w4pl_date day="2" /]

Example 3 – Displaying the date and time 3 hours and 2 days from now. The ‘hour’ parameter is set to ‘3’ and the ‘day’ parameter is set to ‘2’.

[w4pl_date hour="3" day="2" /]

Example 4 – Displaying the date and time in a custom format. The ‘format’ parameter is set to ‘d-m-Y H:i’.

[w4pl_date format="d-m-Y H:i" /]

Example 5 – Displaying the date and time 3 hours from now in a custom format. The ‘hour’ parameter is set to ‘3’ and the ‘format’ parameter is set to ‘d-m-Y H:i’.

[w4pl_date hour="3" format="d-m-Y H:i" /]

These examples showcase the versatility of the w4pl_date shortcode and how it can be customized to fit various needs.

PHP Function Code

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

Shortcode line:

add_shortcode( 'w4pl_date', array( $this, 'date_shortcode' ) );

Shortcode PHP function:

function date_shortcode( $atts = array() ) {
		$args = shortcode_atts(
			array(
				'hour'   => '0',
				'day'    => '0',
				'format' => 'Y-m-d H:i:s',
			),
			$atts
		);

		$adjust = intval( $args['hour'] ) * HOUR_IN_SECONDS + intval( $args['day'] ) * DAY_IN_SECONDS;
		return gmdate( $args['format'], time() + $adjust );
	}

Code file location:

w4-post-list/w4-post-list/includes/shortcodes/class-date-shortcode.php

W4 Post List [postlist] Shortcode

The W4 Post List shortcode is a powerful tool that generates a list of posts based on specified criteria. This shortcode parses attributes, applies filters, and retrieves a list of posts in HTML format. If unsuccessful, it returns an error message.

Shortcode: [postlist]

Examples and Usage

Basic example – A simple usage of the ‘postlist’ shortcode to display a list of posts. The ‘id’ attribute corresponds to the ID of the list you want to display.

[postlist id=1 /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'postlist', array( $this, 'shortcode' ), 6 );

Shortcode PHP function:

function shortcode( $attrs ) {
		$options = $this->parse_shortcode_attrs( $attrs );
		if ( empty( $options ) ) {
			return '';
		}

		$options = apply_filters( 'w4pl/pre_get_options', $options );

		try {
			$list = W4PL_List_Factory::get_list( $options );

			return $list->get_html();

		} catch (Exception $e) {

			// Not showing error.
			return $e->getMessage();
		}
	}

Code file location:

w4-post-list/w4-post-list/includes/shortcodes/class-list-shortcode.php

Conclusion

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