The MU forums have moved to WordPress.org

Using Custom Fields to display DEFAULT IMAGE (thumb) (3 posts)

  1. boonika
    Member
    Posted 15 years ago #

    Right now, posts on user blogs look like little squares. No body text, just category name, title and image (thumb) which gets displayed by using custom fields. I guess that some users will need some time to learn how to use custom field to display their thumbs. So, I thought, it would be cool to have a default image (thumb) displayed when someone forgets to ad key value. An image which would be stored inside theme's 'images' folder.

    This is the code (modified Mimbo theme code) I've used to display one section of posts on user's front page:

    <div id="leftcol">
        <?php
    // this is where the Features module begins
    	query_posts('showposts=0&offset=1'); ?>
        <?php while (have_posts()) : the_post(); ?>
        <div class="feature">
    	<h3><?php
    	  // this is where the name of each category gets printed
    	the_category(', ') ?></h3>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php bloginfo('template_url'); ?>/images/<?php
    // this is where the custom field prints images for each Feature
    	$values = get_post_custom_values("Image"); echo $values[0]; ?>" alt="" /></a><a href="<?php the_permalink() ?>" rel="bookmark" class="title">
          <?php
    // this is where title of the Feature gets printed
    	  the_title(); ?></a></div>
        <?php endwhile; ?>

    EDIT:

    I would just like to add this. Is it possible (it's PHP, of course it is) when writing a post to display only a post image? That way I wouldn't need to use custom fields to display thumbs on front (index.php) page. I would only use them for displaying default images (thumbs).

  2. boonika
    Member
    Posted 15 years ago #

    This could be the solution:

    <?php $image = get_post_meta($post->ID, 'image', true); ?>
    <?php
    if (!empty($image)) {
    echo '<img alt="" src="'.$image.'" />';
    }
    ?>
  3. boonika
    Member
    Posted 15 years ago #

    This amazing plugin does everything. You don?t even need to enter custom value cause it searches for images inside the post and displays its thumbnail. Btw, Justin Tadlock has a lot of interesting plugins besides this one:

    http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin

About this Topic