Support » Plugins » question: image id

  • Resolved arminbw


    Is there an easy way to give every image in a post it´s own css id?

    If the first image always would have id “post1-image1”, the second id “post1-image2”, etc. it would be easy to write a small java-script image-switching-gallery.

    If not, what is the correct WordPress way to access the different images of a post (using php or template tags)?


Viewing 2 replies - 1 through 2 (of 2 total)
  • You didn’t say which version of WordPress. If it’s 2.5, view the source of a page and you’ll see the images already have a few classes. One looks like “wp-image-nn” where nn is (guessing here…) the id of the image in your posts table. So you don’t have to do a thing! Unless you wanted them to have a different naming format.

    Take a peek at the posts table in your database, you’ll find that images uploaded into a post are listed in there, they just have a different type. You could write a query to get them, or poke around in the wp-includes directory for the code that does this to display them in your posts.

    BUT, that said, since you mentioned css ids, I am assuming you’ll start by displaying them all in your post in the HTML.

    So, if you just want to post a batch of images and then on the client side hide all except one and rotate through with JavaScript, you CAN select them with jQuery fairly easily. And manipulate them. Without individual ids. Check it out before you write a lot of JavaScript.

    Writing a plugin to get my own “the_content” was something I was thinking of, but I now decided to stay as much as possible in the theme-layer.

    Without giving every image it´s own id, I am now using getElementById combined with getElementByTagName in a very very tiny javascript
    (And yes, jQuery might be the modern way to do this).

    Thank´s for your hints!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘question: image id’ is closed to new replies.