Title: One Category
Last modified: August 19, 2016

---

# One Category

 *  [ersnyder](https://wordpress.org/support/users/ersnyder/)
 * (@ersnyder)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/one-category/)
 * I am creating an archive page. I am using the loop to display: post date and 
   post title. I have posts that have between 2 to 3 categories assigned to them
   each at any given time. Though, I only have two kinds of posts, ‘articles’ and‘
   links’ which are one of the categories assigned to each post.
 * So, what I am looking to do is; display on the archive page: post date, post 
   title and either ‘article’ or ‘links’. I’m guessing I need to query somehow whether
   or not each post has ‘article’ or ‘links’ assigned to it and then echo that result?
   I am just lost at how to do that.
 * I should also note, I already have the date and title of each post working on
   the archive page. I am just looking to add the category display as well.
 * Thoughts?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/one-category/#post-1339570)
 * In the loop, use [the_category](http://codex.wordpress.org/Template_Tags/the_category)
   to display categories assigned to posts.
 *  Thread Starter [ersnyder](https://wordpress.org/support/users/ersnyder/)
 * (@ersnyder)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/one-category/#post-1339694)
 * Hmmm, maybe I didn’t word that correctly; My posts have at least three categories
   each. However, on my archives page I only want to display one or two specific
   categories assigned to each post…
 * I guess I would like to query the categories assigned to a post and if one of
   the category ID’s equal 7 or 45 then to display only those category names. I’m
   thinking this is getting me close:
 * `<?php foreach((get_the_category()) as $category) { echo $category->cat_name .'';}?
   >`
 * …except I don’t know how to alter it to display one of the two categories I am
   looking for.
 *  Thread Starter [ersnyder](https://wordpress.org/support/users/ersnyder/)
 * (@ersnyder)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/one-category/#post-1339695)
 * This also get’s me close, only displaying one category…
 * `<?php $cat = get_the_category(); $cat = $cat[0]; ?><?php echo $cat->cat_name;?
   >`
 * …which is what I’m after, but it seems to display a random category rather than
   allowing me to target two specific categories no matter how I seem to manipulate
   it.
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/one-category/#post-1339759)
 *     ```
       <?php
       foreach((get_the_category()) as $category) {
         if ( $category->cat_ID == 7 || $category->cat_ID == 345 ) {
           echo $category->cat_name . ' ';
         }
       }
       ?>
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘One Category’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [date](https://wordpress.org/support/topic-tag/date/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [single](https://wordpress.org/support/topic-tag/single/)
 * [title](https://wordpress.org/support/topic-tag/title/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/one-category/#post-1339759)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
