Grow your CSS skills. Land your dream job.

WP: how to change images in post excerpt?

  • # November 11, 2009 at 10:52 pm

    Hi folks,

    I am currently working on my category pages in WordPress and I have managed to style 90% of my posts that show up under a specific category.

    My problem is that I wish to display a different image for each post excerpt (not in the actual post), pretty much like css-tricks has in "video’s" sections, and I do not know where to look in WP Codex to find the relevant php code to call up an assigned image.

    I tried adding a div area in my category.php which defines an area for the image in CSS to sit in, and then in the actual post page (WP Dashboard) I inserted the image with the same class as used in the div. But it only showed up in the actual post full article page and not in the excerpt. This I now know is the wrong way… could anyone point me in the right direction?

    I would be most grateful for any help :)

    # November 12, 2009 at 3:53 am

    I’d put the image in the actuall post content.

    If you’re using the_content() in your categorie-file then remember to put it after the <!–more–>.
    Then use a function on your category-template-file to extract that first image and display it in the div you have going.

    For the function see here: http://www.wprecipes.com/how-to-get-the … display-it
    Put that function in functinons.php of your theme, and call it in your category-file.

    Code:
    # November 12, 2009 at 8:32 am

    Thank you very much for that link TeMc, I will check that out right now and reply back with how I got on later.

    Cheers M :)

    # November 12, 2009 at 1:20 pm

    No luck, I did everything as you suggested and the stuff from the tutorial but it doesn’t seem to display the image only the url source.

    *I tried inserting the img before the <!–more–> tag in the page editor & after it – no joy
    *I tried sticking an image in the Media db area on WP DSB and direct the image to there in stead off my server – no joy
    * Tried making my div container larger – no joy

    May have to look for a plugin instead. Thank you for your help though, appreciated! It may work for me if I do another WP site..

    ==EDIT==
    Sadly that didn’t work, some of the plugins I found were problematic for the style of my post – but I found this alternative which works fine, but it does not link to the first image in your post: http://blogigs.com/display-thumbnail-images-in-post-excerpts/ hope this helps others :)

    # November 15, 2009 at 7:23 am

    Well you could either wait until WordPress 2.9 – when posts get thumbnail images – or use a custom field in your post as found in the article above. .

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".