WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Assign a unique class for every post (3 posts)

  1. harry07
    Member
    Posted 5 years ago #

    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!

  2. ionfish
    Member
    Posted 5 years ago #

    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);

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    ...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).

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags