Title: Add post category class Jquery &#8211; Php ?
Last modified: November 21, 2017

---

# Add post category class Jquery – Php ?

 *  [Aztix](https://wordpress.org/support/users/aztix/)
 * (@aztix)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/add-post-category-class-jquery-php/)
 * Hey all,
 * I call most popular post in my wordpress sidbar. (with a plugin)
 * Each of those post have a category, and i have to look them with there own title
   and category color.
 * So, i need to add post category class to each of them.
 * I’am trying to do that with Jquery, and right this :
 *     ```
       <script>
       jQuery(document).ready(function(){
           jQuery(".wpp-list-with-thumbnails li").addClass("category");
         });
       </script>
       ```
   
 * With this script, each of the post have the class : category.
    And now juste 
   need to add the post category avec this.
 * Is someone know, if it’s possible to do that with Jquery? if it’s not, how do
   u advice me to do ? 🙂
 * Thanks for readers 🙂
    Cheers

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

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [8 years, 6 months ago](https://wordpress.org/support/topic/add-post-category-class-jquery-php/#post-9707056)
 * > I call most popular post in my wordpress sidbar. (with a plugin)
 * What is the HTML for that widget in particular? We don’t want to see hundreds
   of lines of code.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/add-post-category-class-jquery-php/#post-9711799)
 * It’s possible with jQuery if the data you need for assigning a class exists with
   the post somewhere. I believe your intent is to add a category term that relates
   to the post, not to actually add the fixed string “category” as a class like 
   your code does. IMO, using jQuery for this is sub-optimal, you are better off
   using PHP if possible.
 * Is the popular posts plugin your own or one distributed by others? If your own,
   definitely add the appropriate class with PHP. If the plugin is by others, see
   if there is a filter hook or similar extension mechanism that allows you to add
   classes to each post’s HTML container. If not, then maybe jQuery is the way to
   go.
 * For a jQuery solution, as Andrew indicates, we need to see the widget’s HTML 
   output.

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

The topic ‘Add post category class Jquery – Php ?’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/add-post-category-class-jquery-php/#post-9711799)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
