默认情况下,博客文章可以显示在单个页面上。我想自定义一个首页,只在页面的一部分显示帖子。如果可能的话,我如何将我最新的博客文章输出到自定义的div或元素上?
创建自定义循环,类似于以下内容:
http://www.johnmorrisonline.com/how-to-create-a-custom-loop-in-wordpress-using-wp_query/
所以,基本上使用WP_Query来获得帖子列表并通过它循环:
http://codex.wordpress.org/Class_Reference/WP_Query
下面是我如何做到的一个例子:
$args = array(
'posts_per_page' => 3,
'offset' => 0,
'category' => 6,
'category_name' => '',
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true );
$posts_array = get_posts( $args );
// print_r($posts_array);
foreach($posts_array as $current_post){
print_r($current_post); // here you have current post values
}
http://codex.wordpress.org/Template_Tags/get_posts