Modified version of get_the_category to limit the number of categories displayed.


Some times as a theme developers we may have to display only specific number of categories a post is filed in as a large number of categories may break the layout in some cases and sometimes we may have to display only one category.

For example in SWIFT magazine layout, I display one category overlayed on the thumbnail.

Unfortunately WordPress functions get_the_category(), the_category() do not take any arguments and display all the categories the post is filed in. I wrote this small function during the development of swift to echo a specific number of categories a post is filed in. I hope this will help the fellow theme developers

Usage is similar to the_category() function, except we take arguments here.

If you have any questions feel free to drop them in comments

7 thoughts on “Modified version of get_the_category to limit the number of categories displayed.

  1. Great post! Very informative, I was actually having alot of trouble with the Wordpress php functions and even tried hiding the categories with CSS in my website. This mod rocks!
  2. hey, great function!! I was wondering if there is anyway to exclude categories from being listed? Again thanks a lot for the function! it really is great!
  3. Thank you! This came just in time when the higher-ups were asking me if this was possible since some of our posts had a lot of categories attached and thus, messing up the layout. I got it done in 5 minutes after reading this tutorial. :) Good job.
  4. [...] to swiftthemes.com, this function came in handy when I had to modify the way categories were being called in the [...]
  5. I really love this theme, but recently, the swift table seems does't work well, could you help me ?
  6. Hi there, I love your work, I have had the 4.0 version working nicely on my site, and my seo is working really considering I have only had the site running for 1 month. I will move to 5.0 but found it a little buggy for now so I went back to 4. But great job. I like the java slider :) If you want to see my site it is www.healthinformatics.info

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>