• 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

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    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

    (@bcworkz)

    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.