WordPress.org

Ready to get started?Download WordPress

Forums

Images on category pages (5 posts)

  1. kolbaba
    Member
    Posted 3 years ago #

    Hello All!

    If you visit: http://kolbaba.com/category/web/ 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.

    Cheers,

  2. Michael Bishop

    Posted 3 years ago #

    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.

    http://codex.wordpress.org/Post_Thumbnails

    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>');
    }
    add_filter('get_the_excerpt','excerpt_nostrip');
  3. Diogo15
    Member
    Posted 3 years ago #

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

  4. WebTechGlobal
    Member
    Posted 3 years ago #

    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.

  5. agokeren
    Member
    Posted 3 years ago #

    You can try this...

    In header.php:

    <?php
    function catch_that_image() {
    global $post, $posts;
    $first_img = '';
    ob_start();
    ob_end_clean();
    $output = preg_match_all('//i', $post->post_content, $matches);
    $first_img = $matches [1] [0];
    if(empty($first_img)){ //Defines a default image
    $first_img = "http://yourdomain.com/images-default.jpg";
    }
    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]

Topic Closed

This topic has been closed to new replies.

About this Topic