我使用的是两个相同的文件:single.php
和home.php
:
(回路外部)。
(有一个#mainbar
两者中的divsingle posts 和home page 但图像应该有所不同)
<?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>
我以为
home page 将获取其自己的自定义字段的值,但取而代之的是
single post. 这是默认行为还是我做错了什么?
EDIT: 我试着给另一篇文章添加一个值,但图片确实是该文章的一个,而不是另一个,所以问题只是主页。
家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(); ?>