在类别/首页上工作时,我想显示带有图像的帖子的图像和标题。当没有图像时,它会留下一个很大的空白——当然,看起来是空的。。。因此,如果没有图像,我想使用更大的文本作为标题。
有人用WordPress找到了这样做的方法吗?
我的代码是:
<div class="feature-section-1">
<?php $posts = get_posts( "tag=\'tagtitle\'&numberposts=1" ); ?>
<?php if( $posts ) : ?>
<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<a href="<?php echo get_permalink($post->ID); ?>" >
<h3><?php echo $post->post_title; ?></h3>
<div class="false-excerpt-div"><?php the_excerpt(); ?>
</div>
<?php if ( has_post_thumbnail()) : the_post_thumbnail(\'columner-thumb\'); endif; ?>
</a>
<?php endforeach; ?>
<?php endif; ?>
</div>
最合适的回答,由SO网友:JediTricks007 整理而成
This should work.
<div class="feature-section-1">
<?php $posts = get_posts( "tag=\'tagtitle\'&numberposts=1" ); ?>
<?php if( $posts ) : ?>
<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<a href="<?php echo get_permalink($post->ID); ?>" >
<?php if ( has_post_thumbnail() ): ?>
<h3><?php echo $post->post_title; ?></h3>
<div class="false-excerpt-div"><?php the_excerpt(); ?></div>
<?php the_post_thumbnail(\'columner-thumb\'); ?>
<?php else: ?>
<h1><?php echo $post->post_title; ?></h1>
<div class="false-excerpt-div"><?php the_excerpt(); ?></div>
<?php endif; ?>
</a>
<?php endforeach; ?>
<?php endif; ?>
</div>