WordPress: Featured Category shortcode

You can use this shortcode to display a group of posts on any page. For example, you may wish to create a page which displays your most important post categories like this demo. Please note, this is not the same as displaying a category on posts in your menu. For that, please see this guide instead.

To create this shortcode, you will first need to add your posts to categories. You can then display 3 posts from any category by using the shortcode below:

You can place the shortcode in any page/post. This will then display the feature in that position (the shortcode text itself won’t be visible).

This shortcode can include the follow options:

title (required)
The text used for the main section title at the top.

category (optional)
The slug of the category to display. If you do not define a category then your 3 most recent posts will be displayed from all categories.

number (optional)
The number of posts to display in this category. Defaults to 3 if not set in the shortcode.

excerpt (required)
Choose whether to display a post excerpt/summary under the title. Set to “false”, “off” or “0” to stop the excerpt from showing under posts.

excerpt_length (required)
Set to the number of words you would like to display in the excerpt (if enabled). For example excerpt_length=”25″ to show 25 words.

border (optional)
Whether or not you would like the title at the top to include a border. Set to “on” to display.

shape (optional)
The shape of the image. Options: portrait, square or landscape. Defaults to landscape if not set.

view_all_button (optional)
Whether or not to display a “View All” button under the posts. Set to “on” to display. By default this button will show the words “View All”. You can change this by using the view_all_button_text parameter – e.g. view_all_button=”Click here to view more”

For example, here is the shortcode with the border option added:

This would create the following feature on the page:

Click here to see a real example of how 3 shortcodes can create a more dynamic page. The shortcodes used on that page are:

This allows you to create a page which shows a good selection of your posts and content. You may wish to mix this with a static front page to give a more magazine feel to your blog.

Was this article helpful?

15 Comments

  1. Laura

    Hi Phil,
    I would like to have this on my home page, where would I add the code please? Thanks

    1. Phil (pipdig)

      Hi Laura, if you go ahead and create a new page with your desired content (including this shortcode and anything else), then you can assign this to the homepage via this guide.

      1. Laura

        Sorry another question! What is the short code to increase the number of posts displayed? Thanks

        1. Phil (pipdig)

          You can set the number by adding number=”6″ to the shortcode. If you have any other questions just let me know.

      2. Marco

        Hi Phil,
        Any reason why a new post with a category wont show up on the page? Do you have a limit on them? If attach the post to another category, then it displays. But it just wont load on a new one.

        thanks,

        1. Phil (pipdig)

          Hi Marco, are you sure that the post has been assigned to the correct category? I’m not aware of any issues which would stop the post from showing, so it should work as you expect.

          1. Marco

            Yep, just doing the same as always but it juts wont have it. Reading could be about the copy and pasting element.

  2. Peter

    Hi Phil,

    This is exactly what I’m after. I’m trying this on a test page. I’ve created the categories, but where do I put in the shortcode?
    [pipdig_category_section category=”fashion” title=”Latest in Fashion” border=”yes”]

    Thanks

    1. Phil (pipdig)

      Hi Peter, you would place the shortcode within the page content, as if it were any other text. This will then display the feature when you save and view/preview the page on your site. To quote the official WordPress docs:

      “A shortcode is a WordPress-specific code that lets you do nifty things with very little effort. Shortcodes can embed files or create objects that would normally require lots of complicated, ugly code in just one line. Shortcode = shortcut.”

      Let me know if you have any other questions about adding it to the page.

  3. Katy

    Hi Phil – would it be possible to have a shortcode where you could add text/image to the start of each post for sponsorship/affiliate disclosures. This is now a legal requirement and it would be a real pain to have to go back into each post and do this manually. There might be a better way? Thanks!

    1. Phil (pipdig)

      Hi Katy, you could add some text to the start of all posts by using one of the options at ‘pipdig > Theme Hooks’. One of the boxes near the bottom of that page can be used to add text to the start/end of each post. If you’d like to display the text only on specific posts (e.g. from a certain post category only) we can create a custom plugin for you to do that as part of an additional service. Let me know if you would be interested in this.

    1. Phil (pipdig)

      Glad you like it, Adam! I hope you find the shortcode useful 🙂

Leave a comment


Please include a link to your site with every comment. It will help us to give specific and more personalized answers to any questions you have. The link to your website will be visible to support staff only. It will not be shown publicly.