Support » Developing with WordPress » Images on category pages

  • Hello All!

    If you visit: you will see the posts but the images within those articles don’t show up.

    Is there a way to edit the category.php file to account for the image?

    I would like to either have the article show all of it’s contents or perhaps a thumbnail to the left of the posts.

    Make sense?

    Any help appreciated.


Viewing 4 replies - 1 through 4 (of 4 total)
  • Your template is probably using the_excerpt, which strips any html, including images.

    Two options off the top of my head. Modify the_excerpt in your functions.php file to include the img tag, or better, would be to utilize the featured image option and modify the category template to use a thumbnail of the featured image.

    To modify the excerpt function to include img tags (which still would only show if at the beginning of the post)

    // allow certain tags in excerpt
    function excerpt_nostrip($text) {
    	return strip_tags($text, '<img>');

    Why don’t you use Post Thumbnail support in your theme?

    Showing any images in relation to a post is now done with post thumbnails or on the interface is it known as Featured Image.

    If your post meta (custom fields) contained a value that can be used to complete the path to the image on your server, then it is possible to code it directly into your theme but that is a very custom and permanent approach. Such an approach could deal with the situation of an image not existing for a post.

    If your theme uses featured posts/thumbnails but does not handle it not being set very well. You might want to considering some changes to your theme such as a default featured image being used.

    You can try this…

    In header.php:

    function catch_that_image() {
    global $post, $posts;
    $first_img = '';
    $output = preg_match_all('//i', $post->post_content, $matches);
    $first_img = $matches [1] [0];
    if(empty($first_img)){ //Defines a default image
    $first_img = "";
    return $first_img;

    and this on your page to show the image example on archive.php

    <?php echo catch_that_image() ?>

    If in content is there no image, then the default image will be used.

    [Mod: Please stop pimping your site]

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Images on category pages’ is closed to new replies.