我有一个帖子图像系统,其中标题中显示了特定类别的帖子缩略图,博客中会出现一个裁剪版本#preview
, 以及出现在全文中的全尺寸图像。
这三个位置中没有任何一个出现图像,我也不太清楚原因。
功能。php-
<?php
register_sidebar();
if (function_exists(\'add_theme_support\')) {
add_theme_support(\'post-thumbnails\');
set_post_thumbnail_size(140,170);
}
if ( function_exists( \'add_image_size\' ) ) {
add_image_size( \'custom-image\', 440, 265, true ); //(hard cropped)
}
function ravs_get_custom_image( $featured_img ){
global $post, $posts;
$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => 1,
\'post_status\' => null,
\'post_parent\' => $post->ID,
\'exclude\' => $featured_img
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
$img = wp_get_attachment_image( $attachment->ID, \'custom-image\' );
return $img;
}
}else{
echo \'Please attach images to your post\';
}
}
?>
索引。php
<?php echo get_header(\'cait\');;?>
<?php echo get_sidebar();;?>
<div id="blog">
<div class="preview">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post-image">
<?php echo ravs_get_custom_image( get_post_thumbnail_id () ); ?>
</div><!-- end post-image -->
<div class="post">
<h2><?php the_title() ;?></h2>
<span class="post-preview">
<?php the_excerpt(\'read more...\'); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts to list</p>
<?php endif; ?>
</span><!-- end post-preivew -->
<p class="post-meta"><span style="font-family: amatic;">>></span> Posted on <?php the_date(\'M-d-y\'); ?> <span style="font-family: amatic;">>></span> <?php the_tags(\'tags: \', \', \', \'<br />\'); ?></p><!-- end post-meta -->
</div><!-- end post -->
</div><!-- end preview -->
</div><!-- end blog -->
<?php get_footer(); ?>