WordPress.org

Support

Support » Themes and Templates » [Resolved] Assign a unique class for every post

[Resolved] Assign a unique class for every post

  • Hello. I’m trying to make a new theme but I’m stuck. I just want to ask how you can assign a unique class for every single post that appears on the front page without using the the_ID template tag because I want the classes to be static. Help?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Should be pretty simple to do this by writing a function hooking into the post_class filter, e.g.

    function add_unique_post_class($classes, $class, $post_id) {
    $classes[] = "unique_class_$post_id";
    return $classes;
    }

    add_filter('post_class', 'add_unique_post_class', 10, 3);

    …without using the the_ID template tag because I want the classes to be static…

    I don’t get it. Post id’s are static. They don’t change. So why not use the post-id thing as an id (instead of as a class, since an ID makes more sense here).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Assign a unique class for every post’ is closed to new replies.