Forums

Count categories within loop? (2 posts)

  1. shrthnd
    Member
    Posted 3 months ago #

    I need to switch class/text-size of the list of categories - the more categories smaller the text needs to be.

    What I am trying to do is set up a conditional statement depending on how many categories are assigned to a post.

    What is the best/easiest/most effective way to count() the number of categories returned by the_category()?

  2. adiant
    Member
    Posted 3 months ago #

    Although it can be done with the_category, I'd be more inclined to use: count(get_the_category())

    But be sure to read:
    http://codex.wordpress.org/Function_Reference/get_the_category

    The use of get_the_category depends on whether or not you are inside the WordPress loop when you call it. It requires a parameter if you are outside The Loop.

Reply

You must log in to post.

About this Topic