Skip to main content
added 109 characters in body
Source Link

I have a custom post type called "Projekte""Projects" and for it some categories.

I would like to display the category name of the posts in the loop but only once.

I am using this but the category is being displayed on top of every post.

For example if the 2 posts are in the same cetegory, now I see the category name twice in the same loop.

How can I solve it?

My code:

<?php
  $category = the_category();
?>
<h2 style="text-transform: uppercase;">
<?php
  if($i == 1) { 
    echo $category[1]->cat_name; 
  }
  $i++;
?>
</h2>     

Many thanks in advance

I have a custom post type called "Projekte" and for it some categories.

I would like to display the category name of the posts in the loop but only once.

I am using this but the category is being displayed on top of every post.

How can I solve it?

My code:

<?php
  $category = the_category();
?>
<h2 style="text-transform: uppercase;">
<?php
  if($i == 1) { 
    echo $category[1]->cat_name; 
  }
  $i++;
?>
</h2>     

Many thanks in advance

I have a custom post type called "Projects" and for it some categories.

I would like to display the category name of the posts in the loop but only once.

I am using this but the category is being displayed on top of every post.

For example if the 2 posts are in the same cetegory, now I see the category name twice in the same loop.

How can I solve it?

My code:

<?php
  $category = the_category();
?>
<h2 style="text-transform: uppercase;">
<?php
  if($i == 1) { 
    echo $category[1]->cat_name; 
  }
  $i++;
?>
</h2>     

Many thanks in advance

Source Link

Display category name of custom posts only once in the loop

I have a custom post type called "Projekte" and for it some categories.

I would like to display the category name of the posts in the loop but only once.

I am using this but the category is being displayed on top of every post.

How can I solve it?

My code:

<?php
  $category = the_category();
?>
<h2 style="text-transform: uppercase;">
<?php
  if($i == 1) { 
    echo $category[1]->cat_name; 
  }
  $i++;
?>
</h2>     

Many thanks in advance