WordPress.org

Ready to get started?Download WordPress

Forums

Limit get_the_category output (3 posts)

  1. shakingpaper
    Member
    Posted 4 years ago #

    Hi there,

    I am using a bit of code to split my post categories into two sections (only showing the child ones) and am wondering if I am able to limit the output to 3 each (just for the front page) as some posts will have many categories attached to them.

    The snippet I am using is below:

    <?php foreach((get_the_category()) as $childcat) { if (cat_is_ancestor_of(14, $childcat)) { echo '<a href="/category/',$childcat->category_nicename,'/">',$childcat->cat_name,'</a>', ' '; }}
    ?>
  2. sabtvm
    Member
    Posted 4 years ago #

    I am also looking for limiting posts from x no. of cats. For eg, when I Post something, usually I will be adding to more than 3 cats, but in the Single view, below each post content, there will be recent posts (5 nos) from all the categories in which that particular post has been posted. I would like to limit output from recent posts from only 2 cats. Is it possible?

    Pls help.

  3. Satish Gandham
    Member
    Posted 4 years ago #

    This post might help you
    http://swiftthemes.com/2010/02/wordpress/modified-version-of-get_the_category-to-limit-the-number-of-categories-displayed/

    It isn't exactly what you are looking for but it will give you an idea of what to do.

Topic Closed

This topic has been closed to new replies.

About this Topic