WordPress.org

Ready to get started?Download WordPress

Forums

photo replacing date for each post (11 posts)

  1. robtour
    Member
    Posted 8 years ago #

    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, 50x50) 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.

    Thanks!

  2. trashcast
    Member
    Posted 8 years ago #

    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! :)

  3. Nicki Faulk
    Member
    Posted 8 years ago #

    Is this what you two are looking for?

    Image Headlines: http://www.coldforged.org/image-headlines-plugin-for-wordpress-15/

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

  4. robtour
    Member
    Posted 8 years ago #

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

  5. Nicki Faulk
    Member
    Posted 8 years ago #

    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. :(

  6. robtour
    Member
    Posted 8 years ago #

    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.

  7. Nicki Faulk
    Member
    Posted 8 years ago #

    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?

  8. robtour
    Member
    Posted 8 years ago #

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

  9. Mark McKibben
    Member
    Posted 8 years ago #

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

    With:
    <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 http://www.yourdomainname.com/pix/

    Doh! Nitallica beat me to the answer. :)

  10. Nicki Faulk
    Member
    Posted 8 years ago #

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

  11. robtour
    Member
    Posted 8 years ago #

    thanks so much to you both!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags