Limit get_the_category output (3 posts)

  1. shakingpaper
    Posted 6 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
    Posted 6 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
    Posted 6 years ago #

    This post might help you

    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