List category posts Shortcode

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

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

Plugin Icon
List category posts

"List Category Posts is a powerful WordPress plugin designed to display posts from specific categories on your pages and widgets, enhancing content organization."

★★★★☆ (250) Active Installs: 100000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [catlist]

List category posts [catlist] Shortcode

The List Category Posts shortcode allows you to display a list of posts from a specific category. The shortcode function ‘catlist_func’ takes attributes, applies default parameters, and checks for number of posts and pagination settings. If pagination is enabled, it applies the relevant CSS. The function then creates a new instance of CatListDisplayer with the given attributes, and returns the display.

Shortcode: [catlist]

Parameters

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

  • numberposts – Determines the number of posts to display.
  • pagination – Controls whether to show pagination or not.

Examples and Usage

Basic example – A straightforward usage of the ‘catlist’ shortcode to display posts from a specific category. Here, we’re using ‘3’ as the category ID.

[catlist id=3 /]

Advanced examples

Displaying posts from multiple categories. In this example, we’re displaying posts from categories with IDs ‘3’ and ‘5’.

[catlist id="3,5" /]

Limiting the number of posts displayed. Here, we’re displaying only the 5 most recent posts from category ‘3’.

[catlist id=3 numberposts=5 /]

Enabling pagination for the displayed posts. This will add navigation links to view more posts from the specified category.

[catlist id=3 pagination=yes /]

Combining multiple parameters. In this example, we’re displaying the 5 most recent posts from categories ‘3’ and ‘5’, with pagination enabled.

[catlist id="3,5" numberposts=5 pagination=yes /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'catlist', array('ListCategoryPosts', 'catlist_func') );

Shortcode PHP function:

function catlist_func($atts) {
    // Can be filtered using the shortcode_atts_catlist hook.
    $atts = shortcode_atts(self::default_params(), $atts, 'catlist');

    if($atts['numberposts'] == ''){
      $atts['numberposts'] = get_option('numberposts');
    }
    if($atts['pagination'] == 'yes' ||
       (get_option('lcp_pagination') === 'true' &&
        $atts['pagination'] !== 'false') ){
      lcp_pagination_css();
    }
    $catlist_displayer = new CatListDisplayer($atts);
    return $catlist_displayer->display();
  }

Code file location:

list-category-posts/list-category-posts/list-category-posts.php

Conclusion

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