嗨,我想要做的是显示带有缩略图的帖子并显示标题和内容的前三行我想要实现的是这个
Date
thumbnail - title
some content
目前我有特色图片,但我正在努力获取其余部分,只是为了重申我想要左侧的特色图片,旁边是标题日期和旁边的内容。这是目前的样子
这是我的功能
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' ); } //Adds thumbnails compatibility to the theme
set_post_thumbnail_size( 200, 170, true ); // Sets the Post Main Thumbnails
add_image_size( 'recent-thumbnails', 55, 55, true ); // Sets Recent Posts Thumbnails}
function recentPosts() {
$rPosts = new WP_Query();
$rPosts->query('cat=4&showposts=3&orderby=date');
while ($rPosts->have_posts()) : $rPosts->the_post(); ?>
<li>
<a href="<?php the_permalink();?>"><?php the_post_thumbnail('recent-thumbnails'); ?></a>
<h2><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h2>
</li>
<?php endwhile;
wp_reset_query();
}
这是我的CSS
#posts { width:600px; height:auto; float:left; margin-top:20px; font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#080808;}
#posts .news{ width:600px; height:auto; font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#000000; display:inline-block;}
#posts a{ font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#000000; display:inline-block;}
这是我如何在我的 index.php 中调用它
<div class="news">
<?php echo recentPosts(); ?>
</div>