Support » Themes and Templates » photo replacing date for each post

  • Hi, I’ve searched extensively and couldn’t find any way of doing this specifically:

    What I’d like to do is, on the “Connections” theme, where the date is, just insert a small (say, 50×50) image that corresponds to the post id. So I’d go in manually and upload a photo to a folder called /pix, with post1.jpg, post2.jpg, etc.–one image for each post.

    Now it seems fairly basic to use php and the wp variable for post id, and append that to the end of an <img> tag that I’d place in post.php. Is that right? I’ve been trying for hours and can’t seem to get it to work. Any help on this would be so, so appreciated.


Viewing 10 replies - 1 through 10 (of 10 total)
  • I was thinking of doing something similar as well. When calling a category archive, instead of stating the name of the archive in text, is there a way for it to load am image instead? I created some images that I would like to head each particular archive page. It sounds like brobtour’sb question…but if not, just excuse me! 🙂

    Is this what you two are looking for?

    Image Headlines:

    (See section capped “Can I use it for things other than titles?”)

    It looks like the image-headlines-plugin is for rendering the post title as imaged text. I’m talking about popping in a 50×50 icon in the spot the date would be, so you’d see a 50×50 icon, the title next to it, and the post below. Thanks!

    My bad, I misread your first post.

    (Image headlines can render any text, not just headlines though.)

    I’m not sure how to solve yours … but it sounds like maybe something that might can be done (most likely by someone with more experience with WP than me, LOL). One way that comes to mind would be to have a template matching the slug of each post and add the image in the template, but that’s a LOT of templates if you have a lot of posts. 🙁

    No problem. But couldn’t there just be an <img> tag with a php echo of the post id in the main template? I’m just not sure how to write it, but it seems to me that where the date is now, you could have an image swap in based on the post name, like post1.jpg, etc. Does that make sense? I just can’t figure out the php to do it, so I thought maybe someone else could help.

    Oooooooooooooooh, wait. I think I see what you’re saying:

    In your template, replace the date/time code with:

    <img src="/path/to/images/<?php the_ID(); ?>.jpg">

    Is that it?

    That worked! Thanks so much, I really appreciate it. Cheers!

    Maybe try replacing:
    <p class="post-date"><?php the_time('D j M Y'); ?>

    <p class="post-date"><img src="/pix/post<?php the_ID(); ?>.jpg" width="50" height="50" />

    In this case your images should be named postXXX.jpg (where XXX is the ID of the post) and should be in

    Doh! Nitallica beat me to the answer. 🙂

    robtour, no problem. Sorry for the confusion … I’m Southern, so you have to type slowly for me to understand what you’re trying to say. LOL!

    Manzabar’s code is prettier than mine (I’m going from memory and it’s not what it used to be, lol), so you might be better off replacing the whole chunk if it fits your template. 🙂

    thanks so much to you both!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘photo replacing date for each post’ is closed to new replies.