I have a loop that will pull the latest post and its three images (in sidebar in custom fields) followed by excerpts for the other posts.
So, the get_post_meta is looking for the $post->ID to pull the images.
Question: how do I get the_ID into the first part of the loop or what else can I pass on to get_post_meta?
Here's the code:
- index.php
<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php the_title('<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" rel="bookmark">', '</a></h2>'); ?>
<?php the_date() ?>
<?php if ($count == 1) : ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="col-border" id="content-body"><?php the_excerpt_reloaded( 45 ); ?></div>
</div> <!-- /post -->
<?php else : ?>
<div class="content-excerpts" id="content-excerpts h2">
<?php if ( function_exists( 'shorten_text' ) ) shorten_text( 150 ); ?>
</div>
<?php endif; ?>
<?php endwhile; ?>
- and from the sidebar:
<?php $image = get_post_meta($post->ID, 'lg-img', true); ?>
<img src="<?php echo $image; ?>" alt="" />
<?php $image = get_post_meta($post->ID, 'sm-img-left', TRUE); ?>
<img src="<?php echo $image; ?>" alt="" />
<?php $image = get_post_meta($post->ID, 'sm-img-right', TRUE); ?>
<img src="<?php echo $image; ?>" alt="" />
It works just fine in single.php where the loop is simple and has the_ID in it!
I can see why it doesn't work but I don't know how to go about fixing this.
Any help would be really, really appreciated.
Thanks,
Roger