你可以使用wp_get_recent_posts() 获取最新帖子,如:
<h2>Recent Posts</h2>
<ul>
<?php
$args = array( \'numberposts\' => \'5\' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo \'<li><a href="\' . get_permalink($recent["ID"]) . \'" title="Look \'.esc_attr($recent["post_title"]).\'" >\' . $recent["post_title"].\'</a> </li> \';
}
?>
</ul>
然后,使用
get_the_post_thumbnail() 要获取帖子的特色图像,请执行以下操作:
if ( has_post_thumbnail($thumbnail->ID)) {
echo \'<a href="\' . get_permalink( $thumbnail->ID ) . \'" title="\' . esc_attr( $thumbnail->post_title ) . \'">\';
echo get_the_post_thumbnail($thumbnail->ID, \'thumbnail\');
echo \'</a>\';
}
把它们混合在一起,你最终会得到这样的结果:
<h2>Recent Posts</h2>
<ul>
<?php
$args = array( \'numberposts\' => \'5\' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
if ( has_post_thumbnail($recent["ID"])) {
echo \'<li>\' . get_the_post_thumbnail($recent["ID"], \'thumbnail\') . \'</li>\';
}
}
?>
</ul>
最后,添加一些CSS:
ul { list-style: none; }
ul li { display: block; width: 45%; float: left; }
你肯定比我更需要设计这个;-)