Hey guys,

I am new to Wordpress and am having a slight issue. I have a "featured" posts section at the top of my index page that shows 3 recent posts from the featured category. Everything shows up fine except the post image. So I see the "post_summary" and the "post_type" (custom fields) but not the image from "post_image". I enter the picture like: /wp-content/uploads/2010/09/samplepicture.jpg

Any help would be greatly appreciated. Thank you...oh and the code is below : )


This is the code I have in the index.php to make it show up:

<!-- showcase -->
	<div id="showcase">
		<div id="showcase-inner">
			
			<?php $dp_showcase = new WP_Query('cat=' . $dp_featured . '&showposts=3'); ?>
			<?php while ($dp_showcase->have_posts()) : $dp_showcase->the_post(); $more = 0; ?>

			<div class="showcase-post">
				<?php if (get_post_meta($post->ID, 'post_image_value', true)) { ?><img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo get_post_meta($post->ID, "post_image_value", $single = true); ?>&amp;w=290&amp;h=239&amp;zc=1&amp;q=95" alt="<?php the_title(); ?>" /><?php } else if (get_post_meta($post->ID, 'post_showcase_value', true)) { ?><img src="<?php bloginfo('home'); ?><?php echo get_post_meta($post->ID, "post_showcase_value", $single = true); ?>" alt="<?php the_title(); ?>" /><?php } else { ?><img src="<?php bloginfo('template_directory'); ?>/images/showcase-placeholder.jpg" alt="" /><?php } ?>
				<div class="showcase-effects">&nbsp;</div>
				<div class="showcase-details">
					<?php if (get_post_meta($post->ID, 'post_title_value', true)) { ?><h3><?php echo get_post_meta($post->ID, "post_title_value", $single = true); ?></h3><?php } ?>
					<?php if (get_post_meta($post->ID, 'post_type_value', true)) { ?><p><?php echo get_post_meta($post->ID, "post_type_value", $single = true); ?></p><?php } ?>	
				</div>
				<a href="<?php the_permalink() ?>">&nbsp;</a>
			</div>
			<?php endwhile; ?>

						
		</div>			
	</div>
	<!-- /showcase -->

This is the code for the functions.php:

<?php



if ( function_exists('register_sidebar') )
	register_sidebar(1,array(
		'before_widget' => '<div id="%1$s" class="sidebox">',
		'after_widget' => '<br clear="all" /></div>',
		'before_title' => '<div class="sidebox-heading"><h2>',
		'after_title' => '</h2></div>',
	));



// CUSTOM POST FIELDS///////////////////////////////////////////////////////////////////////////////////////////////////////////

$post_custom_fields =
array(
	"post_image" => array(
		"name" => "post_image",
		"std" => "",
		"title" => "Post Image Path (eg. /wp-content/uploads/mypic.jpg):",
		"description" => ""
	),
	"post_showcase" => array(
		"name" => "post_showcase",
		"std" => "",
		"title" => "Showcase Image Path (only required if image resizing is disabled):",
		"description" => ""
	),
	"post_summary" => array(
		"name" => "post_title",
		"std" => "",
		"title" => "Short Title:",
		"description" => ""
	),
	"post_type" => array(
		"name" => "post_type",
		"std" => "",
		"title" => "Post Type (Ex: Tutorial, Freebie, Interview, etc.):",
		"description" => ""
	)

);

function post_custom_fields() {
	global $post, $post_custom_fields;

	foreach($post_custom_fields as $meta_box) {
		$meta_box_value = stripslashes(get_post_meta($post->ID, $meta_box['name'].'_value', true));

		if($meta_box_value == "")
			$meta_box_value = $meta_box['std'];

			echo '<p style="margin-bottom:10px;">';
			echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
			echo'<strong>'.$meta_box['title'].'</strong>';
			echo'<input type="text" name="'.$meta_box['name'].'_value" value="'.attribute_escape($meta_box_value).'" style="width:98%;" /><br />';
			echo '</p>';
	}
}

function create_meta_box() {
	global $theme_name;
		if ( function_exists('add_meta_box') ) {
			add_meta_box( 'new-meta-boxes', 'Additional Information', 'post_custom_fields', 'post', 'normal', 'high' );
	}
}

function save_postdata( $post_id ) {
	global $post, $post_custom_fields;

	foreach($post_custom_fields as $meta_box) {
		// Verify
		if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
			return $post_id;
	}

	if ( 'page' == $_POST['post_type'] ) {
		if ( !current_user_can( 'edit_page', $post_id ))
			return $post_id;
		} else {
		if ( !current_user_can( 'edit_post', $post_id ))
			return $post_id;
	}

	$data = $_POST[$meta_box['name'].'_value'];

	if(get_post_meta($post_id, $meta_box['name'].'_value') == "")
		add_post_meta($post_id, $meta_box['name'].'_value', $data, true);
	elseif($data != get_post_meta($post_id, $meta_box['name'].'_value', true))
		update_post_meta($post_id, $meta_box['name'].'_value', $data);
	elseif($data == "")
		delete_post_meta($post_id, $meta_box['name'].'_value', get_post_meta($post_id, $meta_box['name'].'_value', true));
	}
}

add_action('admin_menu', 'create_meta_box');
add_action('save_post', 'save_postdata');

try this:
custom field name: post_image_value value: yourimageurl
custom field name: post_title_value value: your post title

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.