List Category Posts allows you to list posts by category and many other parameters in a post, page or widget. You use the [catlist] shortcode to selec …
List Category Posts allows you to list posts by category in a post or page using the [catlist]
shortcode. When you’re editing a page or post, directly insert the shortcode in your text and the posts will be listed there. The basic usage would be something like this:
[catlist id=1] [catlist name="news"]
The shortcode accepts a category name or id, the order in which you want the posts to display, and the number of posts to display. You can also display the post author, date, excerpt, custom field values, even the content! A lot of parameters have been added to customize what to display and how to show it. Check the full documentation to learn about the different ways to use it.
The [catlist]
shortcode can be used as many times as needed with different arguments on each post/page.
[catlist id=1 numberposts=10]
There’s an options page with only one option -for the moment-, new options will be implemented on demand (as long as they make sense). Right now the only global option is the numberposts
parameter, to define a default number of posts to show for each instance (you can override this value by using the numberposts
parameter in your shortcode).
Read the instructions to learn which parameters are available and how to use them.
If you want to List Categories instead of posts you can use my other plugin List categories.
You can find Frequently Asked Questionshere.
Customization
The different elements to display can be styled with CSS. you can define an HTML tag to wrap the element with, and a CSS class for this tag. Check the documentation for usage. You can also check this nice tutorial which gives lots of tips and how-to’s to customize how to display the posts.
Great to use WordPress as a CMS, and create pages with several categories posts.
GUI
Klemens Starybrat has created a GUI for List Category Posts. It helps you create a shortcode from a nice visual interface in WordPress’ text editor. Check it out:
GUI for List Category Posts
AJAX pagination
The ajax pagination feature is maintained in an add-on plugin by Klemens Starybrat. Check it out:
LCP Ajax Pagination
Widget
Since WordPress 4.9, you can use shortcode in text widgets. So you can just add a text widget in Appearence > Widgets and write the List Category Posts shortcode.
The plugin also includes a widget as a simple interface for its functionality. Just add as many widgets as you want, and select all the available options from the Appearence > Widgets page. Not all the functionality in the shortcode has been implemented in the widget yet. You can use the shortcode for the most flexibility.
Please, read the information on the wiki and Changelog to be aware of new functionality, and improvements to the plugin.
Videos
Some users have made videos on how to use the plugin (thank you, you are awesome!), check them out here:
Support the plugin
Klemens Starybrat has been writing lots of amazing code for this plugin, so if you’ve found it useful and want to pay it forward, consider sponsoring him on GitHub: https://github.com/sponsors/klemens-st
I have a PayPal account where you can donate too.
Development
Development is being tracked on GitHub. Fork it, code, make a pull request, suggest improvements, etc. over there. I dream of the day all of the WordPress plugins will be hosted on Git π
Since the documentation on how to use the plugin has passed wordpress.org’s character limit, the text was cut. I’ve since started using a wiki for more comfortable reading and maintaining. Please check it out, suggestions are welcome on GitHub issues!
Below you can find common shortcode use cases. You can use the shortcode while editing posts, pages, custom post types, text widgets and in all “page builder” plugins that support shortcodes.
Read the full documentation to discover many more features, including:
List 10 latest posts:
[catlist]
The default number of listed posts is 10, to modify it you need to specify numberposts
parameter:
[catlist numberposts=15]
List posts from the “Dogs” category:
[catlist name=Dogs]
List posts from the category with id 2
:
[catlist id=2]
By default only the “post” post type is included. To list pages use:
[catlist post_type=page]
and for both posts and pages:
[catlist post_type="post,page"]
If we combine the above options we can get a shortcode that lists 15 items, including post and pages, from the “Dogs” category:
[catlist name=Dogs post_type="post,page" numberposts=15]
Most of the parameters you will find in the documentation can be used together.
The plugin can detect current post’s category and use it for listing:
[catlist categorypage=yes]
Same goes for tags:
[catlist currenttags=yes]
To show each post’s excerpt use:
[catlist excerpt=yes]
If you want to show the date, author and comments count next to each post, use:
[catlist date=yes author=yes comments=yes]
You can specify html tags and classes for many elements. Let’s modify the previous shortcode and wrap dates and authors in tags and classes of our choice:
[catlist date=yes date_tag=span date_class="my-date" author=yes author_tag=p author_class="my-author" comments=yes]
You can order posts by date:
[catlist orderby=date]
You can also use title
, author
, ID
. More options are described in the documentation.
The plugin also supports pagination. You need to specify numberposts
to tell the plugin how many posts per page you want:
[catlist pagination=yes numberposts=5]
See the wiki: Pagination for more information.
Please read the full documentation for detailed documentation of all plugin features, use cases and shortcode parameters.
list-category-posts
directory to your wp-content/plugins/ directory.You can find the Frequently Asked Questions here.
Check out the Wiki
Please read the instructions and the FAQ before opening a new topic in the support forums.
The widget is quite simple, and it doesn’t implement all of the plugin’s functionality.
Since WordPress 4.9, you can use a shortcode in a widget. If you’re using a previous WordPress version, add this code to your theme’s functions.php file:
add_filter('widget_text', 'do_shortcode');
Then just add a new text widget to your blog and use the shortcode there as the widget’s content.
How to customize the way the posts are shown: Template System.
You can post them on GitHub Issues.
Please check the FAQ before posting a question. You can post questions in the Support forum or add a new issue on GitHub.
excludeposts=this
raised PHP warnings when navigating to non-post pages.main_cat_only=yes
to select only the posts that have this category as their main one (#449).currenttags
, currentterms
has been added to support filtering by current post’s custom taxonomy terms (#293).keep_orderby_filters=yes
to prevent the plugin from removing ‘posts_orderby’ filters added by other plugins/themes.ignore_sticky_posts=yes
to ignore all sticky posts, they will still be displayed as regular posts in normal order if they match your filtering options, though. (#342)cat_sticky_posts=yes
to make sticky posts ‘stick’ when filtering by category. (#423)[catlist posts_cats=yes posts_cats_class="feed categories"]
now work.link_current=no
to prevent the current post from being wrapped in a link.posts_cats
and posts_tags
, a bunch of new parameters have been added to customise this feature, see the docs.currenttags
, when navigating to a post with no tags, no posts are displayed, same as with categorypage
.customfield_orderby
, use customfield_orderby_type
. Thanks @vosykapavel!main_query=no
. See the docs and #445.target
attribute from <a>
elements in post titles (#464) .post_parent=0 post_type=page
now works as expected, displaying only top level pages (#370).shortcode_atts_catlist
, see the docs.lcp_pagination_html
, see the source.[catlist includeposts="2,97"]
. Thanks @hvianna!customfield_compare
, see the docs for instructions.category_description
with category_description_tag
and category_description_class
.content=yes
to <div>
to avoid generating invalid HTML (previously <p>
).excerpt_full
not being run through the_excerpt
filters (thanks @StefanXRoos!). The filters are now applied same as for excerpt_yes
. Please check your setup if you are using excerpt_full
.display_id
bug, thanks for reporting @fiestoforo!posts_where
filter not being properly removed when using starting_with
.This is a big release since @zymeth25 and I have been doing lots of refactoring based on maintainability, code quality and testing. It means the code is much cleaner and easier to maintain. So fixing bugs or adding new features should be easier now. If you find any issues, please report them on GitHub (https://github.com/picandocodigo/List-Category-Posts/issues).
include
, updated the build, bumped versions, added tests, and more.customfield_display_glue
was shown even when the custom field values were empty – https://wordpress.org/support/topic/hide-the-glue-content-if-costum-fields-are-emptyand
relationship.ol_offset
, when you use an ordered list, you can set an offset so the posts will start from that number instead of 1.[catlist author_posts="fernando"]
. If you want to select posts from several authors, you need to use the author id instead. You can find the id for each author in wp-admin/users.php
. It needs to be a comma separated value, example: [catlist author_posts="1,2"]
excludeposts
function. It wasn’t working very well with this
.get_the_post_thumbnail_url
. But thanks to a post in the support forum, I noticed we lost some of the sizing functionality in get_the_post_thumbnail
. So this version goes back to using get_the_post_thumbnail but keeping the new alt attribute for thumbnails.<span class="lcp_private"> private</span>
, so you can customize the CSS (hide it, change its color, etc.).categorypage
now suppports yes
for all post’s categories with OR relationship, all
for AND relationship and other
to get all categories except current categories (with OR relationship) (thanks @zymeth25! π)before=today
, when you use it the plugin will get today’s date dynamically and display only old posts. Thanks @nnasirzada for the PR implementing this!lcp_page_link
somewhere or customized the lcp-paginator.php
file somehow, watch out because we refactored this function. Also, let us know what you changed to see if we can incorporate it in the core plugin πbefore
and after
are now working againcreate_function
in PHP 7author_post
and search
parameters.custom_fields
and customfield_orderby
. Please check the readme for more information.lcp_prevlink
and lcp_nextlink
. Thanks @zymeth25.[catlist categorypage="yes"]
had stopped working with WordPress 4.9. This is because the category check would compare a return value against the “Empty Term” translation key which was changed in this commit adding periods at the end of some error messages. So it was just a matter of adding the period in the if condition. Thanks helmutka for reporting this!Several bug fixes:
tags_as_class
instance variable is defined. This squelched an ‘undefined index’ PHP Notice that appeared for widgets that were last saved before upgrading to 0.71.1. Fix by Matthew Eppelsheimer (@MatthewEppelsheimer on GitHub).excerpt_tag
but not excerpt_class
, excerpt will be wrapped with given tag.excerpt_tag
and excerpt_class
, excerpt will be wrapped with provided tag and given class.excerpt_class
but not excerpt_tag
, excerpt will be wrapped with a span and the given class.Notice: Undefined offset: 0 in /include/lcp-category.php on line 69
Thanks @mmatthews1981, @ottadvantage and @mhoeher for their contributions on this version:
lcp_currentpage
.[catlist taxonomy='person' terms='bob']
. This might break some current uses of taxonomy, but since it was written so long ago and I don’t know why it used “tags”, I decided to just create the ‘terms’ parameter. People using the custom taxonomies were people who are looking at the code anyway since I can’t find it documented anywhere. Sorry for the inconveniences!customfield_display_separately
, customfield_display_glue
and customfield_display_name_glue
parameters for multiple custom fields handling by bibz. Thanks! πThanks Sophist from UK for this release π
By Sophist:
Other minor fixes by me.
post_status
and post_type
parameters for using multiple post statuses and types.author_posts_link
, to show an author’s page.display_id
parameter. Set it to yes to show the Post’s ID next to the post title.starting_with
parameter. Gets posts whose title start with a given letter.template
parameter.pagination_prev
and pagination_next
params to customizeno_posts_text
param to display a custom message when nocustomfield_display_name
param.more
tag. If there’s a <!–more–> tag in the post, then it will behave just as WordPress does: only show the content previous to the more tag.[catlist id=1+2-3]
will include posts from categories 1 and 2 but not 3.customfield_orderby
parameter.post_status
, it used to show all published posts and if user was logged in, all private ones too. Now you can specify ‘private’ to just display private posts, and draft, publish, draft, etc (See post_status param on the instructions for more info).[catlist name=nintendo catlink=yes category_count=yes]
– https://wordpress.org/support/topic/count-featureexcerpt_strip=no
. Added a new parameter to have a consistent excerpt. If you want to overwrite WordPress’ excerpt when using the plugin and generate one the way the plugin does when there’s no excerpt, use excerpt_overwrite=yes
.excerpt_strip=yes
.This update is dedicated to Michelle K McGinnis who bought me “Diamond Age” by Neal Stephenson from my Amazon Wishlist. Thanks! π
= …