How to display only primary category of post

Hi. I am using following snippet to display category/taxanomy of a post and it shows all categories of post including child and parents.

<Taxonomy category>  <Term title /> </Taxonomy>

However, i want to diplay only primary category of post. How to achieve that?

Hi! You could use the parent parameter:

<Taxonomy category parents=true>
    <Term title /> 
</Taxonomy>

or if you want to see just the main categories you have available you can use a loop:

<Loop taxonomy=category parents=true >
  <Term title /> <br/>
</Loop>

However, if you already have your post loop you can try adding the first option I wrote:

<Loop type=post>
  <Taxonomy category parents=true>
    <Term title />
  </Taxonomy>
</Loop>

More fields & parameters here

Let me know how it goes!

2 Likes