Support » Fixing WordPress » If Catagories > 3 don't display code…

  • Hello WordPress & Coding Gurus,

    When I post an item in my blog, I have the catagories displayed below the post title. For reasons I won’t go into, I sometimes may have up to 100 catagories selected for an individual post.

    In the cases where there are 3 or more (say) catagories for a post, I don’t want it to display all of them.

    Ugh, that sounds messy! If you followed, is such a thing possible?

    Many thanks.

Viewing 1 replies (of 1 total)
  • Michael


    Forum Moderator

    to limit the category output to three,
    try to use a filter function, added to functions.php of your theme:


    // limit output to max 3 categories in the loop
    function the_category_max_output($output) {
    	if( in_the_loop() ) :
    	$list = explode('</a>',$output); $output = '';
    	for( $i; $i < min(3,count( $list )); $i++ ) {
    	$output .= array_shift($list).'</a>'; }
      return $output;
Viewing 1 replies (of 1 total)
  • The topic ‘If Catagories > 3 don't display code…’ is closed to new replies.