Below, you’ll find a detailed guide on how to add the Series 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 Series Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Series Plugin and the shortcodes it provides:
"Series is a WordPress plugin that efficiently categorizes and organizes your content into a systematic series format, boosting user navigation and engagement."
- [series_list_posts]
- [series_list_related]
- [the-series]
Series [series_list_posts] Shortcode
The Series List Posts shortcode is a dynamic tool that displays a list of posts within a specific series. The shortcode attributes allow customization of the post order, sorting method, and the number of posts displayed. It uses a default setting if no attributes are provided. The ‘echo’ attribute is set to ‘false’, enabling the output to be returned instead of printed.
Shortcode: [series_list_posts]
Parameters
Here is a list of all possible series_list_posts shortcode parameters and attributes:
series
– Name of the series to display posts from.order
– Defines post order, ‘ASC’ for ascending, ‘DESC’ for descending.orderby
– Specifies the parameter to sort posts, like ‘date’, ‘title’ etc.posts_per_page
– Number of posts to show per page, ‘-1’ shows all posts.
Examples and Usage
Basic example – A simple usage of the series_list_posts shortcode to list all posts in a series, ordered by date in ascending order.
[series_list_posts series="my-series" /]
Advanced examples
Using the shortcode to list posts in a specific series, ordered by title in descending order.
[series_list_posts series="my-series" orderby="title" order="DESC" /]
Setting a limit on the number of posts listed by the shortcode. In this example, only the first 5 posts in the series will be listed.
[series_list_posts series="my-series" posts_per_page=5 /]
Combining multiple parameters to customize the output of the shortcode. This example lists the first 5 posts in a series, ordered by title in descending order.
[series_list_posts series="my-series" orderby="title" order="DESC" posts_per_page=5 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [series_list_posts]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'series_list_posts', __NAMESPACE__ . '\list_posts_shortcode' );
Shortcode PHP function:
function list_posts_shortcode( $attr = array() ) {
$defaults = array(
'series' => '',
'order' => 'ASC',
'orderby' => 'date',
'posts_per_page' => -1,
);
$attr = shortcode_atts( $defaults , $attr, 'series_list_posts' );
$attr['echo'] = false;
return list_posts( $attr );
}
Code file location:
series/series/inc/functions-shortcodes.php
Series [series_list_related] Shortcode
The Series List Related shortcode is a powerful tool in WordPress that lists related posts within a series. This shortcode allows you to customize the order and number of related posts displayed. By default, it lists all related posts in ascending order by date. But, you can easily change these parameters to fit your needs. The ‘echo’ attribute is set to false, meaning the list won’t be displayed directly. Instead, it’s returned as a value for further use. This makes the shortcode very flexible and adaptable for various uses.
Shortcode: [series_list_related]
Parameters
Here is a list of all possible series_list_related shortcode parameters and attributes:
order
– Defines the sequence of posts, ‘ASC’ for ascending, ‘DESC’ for descendingorderby
– Determines the parameter for sorting posts, ‘date’ for sorting by dateposts_per_page
– Sets the number of posts per page, ‘-1’ to display all posts
Examples and Usage
Basic example – The following shortcode lists all related posts in ascending order by date with no limit on the number of posts displayed.
[series_list_related /]
Advanced examples
The following shortcode lists all related posts in descending order by date with a limit of 10 posts displayed.
[series_list_related order="DESC" posts_per_page=10 /]
The next shortcode lists all related posts in ascending order by title with no limit on the number of posts displayed.
[series_list_related orderby="title" /]
Lastly, this shortcode lists all related posts in descending order by title with a limit of 5 posts displayed.
[series_list_related orderby="title" order="DESC" posts_per_page=5 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [series_list_related]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'series_list_related', __NAMESPACE__ . '\list_related_shortcode' );
Shortcode PHP function:
function list_related_shortcode( $attr = array() ) {
$defaults = array(
'order' => 'ASC',
'orderby' => 'date',
'posts_per_page' => -1,
);
$attr = shortcode_atts( $defaults , $attr, 'series_list_related' );
$attr['echo'] = false;
return list_related_posts( get_the_ID(), $attr );
}
Code file location:
series/series/inc/functions-shortcodes.php
Series [the-series] Shortcode
The ‘the-series’ shortcode is a WordPress function that generates a list of terms associated with a post in a series. This shortcode uses the ‘get_the_term_list’ function to retrieve the term list for the current post. It accepts three parameters – ‘before’, ‘after’, and ‘separator’, which are used to format the output. By default, terms are separated by a comma.
Shortcode: [the-series]
Parameters
Here is a list of all possible the-series shortcode parameters and attributes:
before
– Text or HTML to display before the series listafter
– Text or HTML to display after the series listseparator
– Character or text to separate each series
Examples and Usage
Basic example – The given shortcode displays a list of series associated with a post. The default separator is a comma.
[the-series /]
Advanced examples
Customizing the separator and adding text before and after the series list. In this example, the separator is a semicolon, and the series list is wrapped with the text “Series: ” and “End of series”.
[the-series before='Series: ' separator='; ' after=' End of series.' /]
Using the shortcode to display a series list without any separator. This can be useful when you want to display the series in a block or in a format where the series names are enough as separators.
[the-series separator='' /]
Adding text before the series list without any separator or after text. This example demonstrates how to use the ‘before’ attribute without using the ‘after’ or ‘separator’ attributes.
[the-series before='Series: ' /]
PHP Function Code
In case you have difficulties debugging what causing issues with [the-series]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'the-series', __NAMESPACE__ . '\the_series_shortcode' );
Shortcode PHP function:
function the_series_shortcode( $attr ) {
$attr = shortcode_atts(
array(
'before' => '',
'after' => '',
'separator' => ','
),
$attr,
'the-series'
);
return get_the_term_list( get_the_ID(), 'series', $attr['before'], $attr['separator'], $attr['after'] );
}
Code file location:
series/series/inc/functions-shortcodes.php
Conclusion
Now that you’ve learned how to embed the Series 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.
Leave a Reply