默认情况下,博客帖子可以显示在单个页面上。 我想自定义首页并仅在我的页面部分显示帖子。 如果可能,我如何将我最新的博客文章输出到自定义div或元素?
答案 0 :(得分:1)
创建自定义循环,如下所示:
http://www.johnmorrisonline.com/how-to-create-a-custom-loop-in-wordpress-using-wp_query/
所以,基本上使用WP_Query来获取post和loop的列表:
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
}