Title: Posts with multiple categories
Last modified: August 21, 2016

---

# Posts with multiple categories

 *  Resolved [DuncanS](https://wordpress.org/support/users/duncans/)
 * (@duncans)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/posts-with-multiple-categories/)
 * Firstly, thanks for creating such a great plugin. It’s exactly what I needed &
   I can’t believe more people don’t use it.
 * Just one thing – when a post has multiple categories assigned to it, the category
   key only seems to show it in the first category registered to it. Is there any
   way around this so that the same post shows up for more than one category when
   using the category key?
 * Thanks!
 * [http://wordpress.org/plugins/post-tiles/](http://wordpress.org/plugins/post-tiles/)

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

 *  [jeegrobot](https://wordpress.org/support/users/jeegrobot/)
 * (@jeegrobot)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/posts-with-multiple-categories/#post-4563349)
 * I’ve found the solution. In the file post-tiles.php you have to change this code(
   more or less line 539)
 *     ```
       $category = get_the_category();
       	      $category_name = $category[0]->cat_name;
       	      $category_slug = $category[0]->slug;
   
       	      // Recovering Saved Color Values
       	      // Define the Settings for recording
       	      $cat_var = "cat_".$category_slug;
       ```
   
 * into this
 *     ```
       $category_name = $category[0]->name;
       	      $category_slug = $category[0]->slug;
       	      $category_name1 = $category[1]->name;
       	      $category_slug1 = $category[1]->slug;
       	      $category_name2 = $category[2]->name;
       	      $category_slug2 = $category[2]->slug;
   
       	      // Recovering Saved Color Values
       	      // Define the Settings for recording
       	      $cat_var = "cat_".$category_slug;
       	      $cat_var1 = "cat_".$category_slug1;
       	      $cat_var2 = "cat_".$category_slug2;
       ```
   
 * Then you have to change this (more or less line 575)
 *     ```
       $featured_style = "style='background-image: url(".$url."); background-size: contain;' class='featured-image ".$animation_style." ".$cat_var."'";
       		      } else {
       				  $featured_style = "class='".$cat_var."'";
       			  }
       ```
   
 * into this
 *     ```
       $featured_style = "style='background-image: url(".$url."); background-size: contain;' class='featured-image ".$animation_style." ".$cat_var." ".$cat_var1." ".$cat_var2." '";
       		      } else {
       				  $featured_style = "class='"".$cat_var." ".$cat_var1." ".$cat_var2."'";
       			  }
       ```
   
 * The line numbers could be different because I’ve made a lot of changes. In this
   way you could add up to three categories.
 *  Thread Starter [DuncanS](https://wordpress.org/support/users/duncans/)
 * (@duncans)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/posts-with-multiple-categories/#post-4563351)
 * Hi jeegrobot
 * Thanks very much for sharing your work on this – I really appreciate it. A couple
   of things – in the second section when you write $featured_style = “class='””–
   do you mean $featured_style = “class='” (ie without the second quotation mark)?
   My site crashed when I copied and pasted your code. When I removed the 2nd quotation
   mark, the site worked, but then my thumbnail sizes were distorted… Any thoughts?
 * Thanks very much
 * Duncan
 *  [jeegrobot](https://wordpress.org/support/users/jeegrobot/)
 * (@jeegrobot)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/posts-with-multiple-categories/#post-4563352)
 * Ops sorry, I made a mistake. Leave the whole part after `} else {` like it is
   originally and it works.
 * You can see it working here [http://www.mambotango.eu/demo/mesh/meshers-list](http://www.mambotango.eu/demo/mesh/meshers-list)
   where people have three different custom taxonomies: Industry (IT, etc.) Company(
   AdProfit, Mesh, etc.) and the last one that is empty for the moment.
 *  Thread Starter [DuncanS](https://wordpress.org/support/users/duncans/)
 * (@duncans)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/posts-with-multiple-categories/#post-4563356)
 * Hi jeegrobot
 * Thanks for the update. I’ve made the changes you suggested & it’s not working
   for me at all. Now even the single category posts aren’t being highlighted when
   I click on a category…
 * Thanks for the suggestions though.
 * Duncan
 *  Thread Starter [DuncanS](https://wordpress.org/support/users/duncans/)
 * (@duncans)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/posts-with-multiple-categories/#post-4563357)
 * Hi again jeegrobot
 * I’ve found what the problem is. You need to make sure that the line “$category
   = get_the_category();” is *not removed* – then everything works. Great!
 * Thanks again
 * Duncan
 *  [jeegrobot](https://wordpress.org/support/users/jeegrobot/)
 * (@jeegrobot)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/posts-with-multiple-categories/#post-4563358)
 * Hi Duncan,
 * sorry for having done a little mess. Yesterday I was a little tired and I copied
   the code in a wrong way. I noticed it only now by reviewing your post.
 * In line 539 (more or less) change this
 *     ```
       $category = get_the_category();
       	      $category_name = $category[0]->cat_name;
       	      $category_slug = $category[0]->slug;
   
       	      // Recovering Saved Color Values
       	      // Define the Settings for recording
       	      $cat_var = "cat_".$category_slug;
       ```
   
 * to this
 *     ```
       $category = get_the_category();
                     $category_name = $category[0]->name;
       	      $category_slug = $category[0]->slug;
       	      $category_name1 = $category[1]->name;
       	      $category_slug1 = $category[1]->slug;
       	      $category_name2 = $category[2]->name;
       	      $category_slug2 = $category[2]->slug;
   
       	      // Recovering Saved Color Values
       	      // Define the Settings for recording
       	      $cat_var = "cat_".$category_slug;
       	      $cat_var1 = "cat_".$category_slug1;
       	      $cat_var2 = "cat_".$category_slug2;
       ```
   
 * In my previous post the first line was missing.
 * Then, on line 575
 *     ```
       $featured_style = "style='background-image: url(".$url."); background-size: contain;' class='featured-image ".$animation_style." ".$cat_var."'";
       ```
   
 * into this
 *     ```
       $featured_style = "style='background-image: url(".$url."); background-size: contain;' class='featured-image ".$animation_style." ".$cat_var." ".$cat_var1." ".$cat_var2." '";
       ```
   
 * Sorry for the mistakes. This should work.
 *  Thread Starter [DuncanS](https://wordpress.org/support/users/duncans/)
 * (@duncans)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/posts-with-multiple-categories/#post-4563359)
 * Great – thanks. All working perfectly now – you can see it in action on the [recent work](http://www.duncansoar.com/recent-work/)
   section of my site.

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

The topic ‘Posts with multiple categories’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/post-tiles_ad9991.svg)
 * [Post Tiles](https://wordpress.org/plugins/post-tiles/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/post-tiles/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/post-tiles/)
 * [Active Topics](https://wordpress.org/support/plugin/post-tiles/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/post-tiles/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/post-tiles/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [DuncanS](https://wordpress.org/support/users/duncans/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/posts-with-multiple-categories/#post-4563359)
 * Status: resolved