I'm using this same come in two files: single.php and home.php:
(Outside of the loop).
(There is a #mainbar div in both single posts and home page but the image should be different)
<?php // Set and display custom field
$mainbar_right_title = get_post_meta($post->ID, 'Mainbar Right Title', true);
$mainbar_right_image = get_post_meta($post->ID, 'Mainbar Right Image', true); ?>
<div class="float-right">
<h2><?php echo $mainbar_right_title; ?></h2>
<img src="<?php echo $mainbar_right_image ?>" alt="" />
</div> <?php
?>
</div>
I thought the home page would get the value of its own custom field but instead is getting the value of the single post. Is this a default behaviour or I'm doing something wrong?
EDIT: I tried adding a value to another single post and the image is indeed the one of the post not of the another so the problem is only the home page.
home.php:
<?php
/**
* Template Name: Home
* @package WordPress
* @subpackage Prominent
* @since Prominent 1.0
*/
get_header(); ?>
<?php get_sidebar(); ?>
<div id="content">
<?php // Insert image using custom field
$postimageurl = get_post_meta($post->ID, 'Intro Image', true); ?>
<div class="block-1">
<img src="<?php echo $postimageurl; ?>" alt="Post Pic" />
</div> <?php
?>
<?php // Start the Loop
if ( have_posts() ) while ( have_posts() ) : the_post();
?> <div class="block-2 padding-top">
<?php the_content(); ?>
</div><!-- .entry-content -->
<?php endwhile; // end of the loop. ?>
<?php // Create and run custom loop
$custom_posts = new WP_Query();
$custom_posts->query('post_type=blocks&location=Front Page§ion=Mainbar');
while ($custom_posts->have_posts()) : $custom_posts->the_post();
?> <div class="block-2 border-top">
<h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php endwhile; ?>
<?php // Set and display custom field
$mainbar_left_title = get_post_meta($post->ID, 'Mainbar Left Title', true);
$mainbar_left_image = get_post_meta($post->ID, 'Mainbar Left Image', true); ?>
<div class="float-left">
<h2><?php echo $mainbar_left_title; ?></h2>
<img src="<?php echo $mainbar_left_image ?>" alt="" />
</div> <?php
?>
<?php // Set and display custom field
$mainbar_right_title = get_post_meta($post->ID, 'Mainbar Right Title', true);
$mainbar_right_image = get_post_meta($post->ID, 'Mainbar Right Image', true); ?>
<div class="float-right">
<h2><?php echo $mainbar_right_title; ?></h2>
<img src="<?php echo $mainbar_right_image ?>" alt="" />
</div> <?php
?>
</div>
<?php // Create and run custom loop
$custom_posts = new WP_Query();
$custom_posts->query('post_type=blocks&location=Front Page§ion=Sidebar');
while ($custom_posts->have_posts()) : $custom_posts->the_post();
?> <div class="block-3 border-top">
<h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail(); ?></a>
<p><?php the_excerpt(); ?></p>
<p><?php echo get_post_meta($post->ID, "Other_Work", true); ?></p>
</div>
<?php endwhile; ?>
<?php // Create and run custom loop
$custom_posts = new WP_Query();
$custom_posts->query('post_type=blocks&location=Front Page§ion=Featured');
while ($custom_posts->have_posts()) : $custom_posts->the_post();
?> <div class="block-2 border-top block-height-2">
<h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail('large'); ?></a>
<p><?php the_excerpt(); ?></p>
</div>
<?php endwhile; ?>
<?php // Create and run custom loop
$custom_posts = new WP_Query();
$custom_posts->query('post_type=blocks&location=Front Page§ion=Content');
while ($custom_posts->have_posts()) : $custom_posts->the_post();
?> <div class="block-3 border-top block-height-2">
<h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail(); ?></a>
<p><?php the_excerpt(); ?></p>
<p><?php the_meta(); ?></p>
</div>
<?php endwhile; ?>
</div><!-- #content -->
<?php get_footer(); ?>
