Worepress文章调用

调用最新发表的文章

query('showposts=30'); //显示数量 ?> have_posts()) : $recentPosts->the_post(); ?>

调用指定分类下的文章(支持翻页)

functions.php 添加:

/** * 分页 / function doocii_pagination($numpages = '', $pagerange = '', $paged='') { if (empty($pagerange)) { $pagerange = 2; } /* * This first part of our function is a fallback * for custom pagination inside a regular loop that * uses the global $paged and global $wp_query variables. * * It's good because we can now override default pagination * in our theme, and use this function in default quries * and custom queries. / global $paged; if (empty($paged)) { $paged = 1; } if ($numpages == '') { global $wp_query; $numpages = $wp_query->max_num_pages; if(!$numpages) { $numpages = 1; } } /* * We construct the pagination arguments to enter into our paginate_links * function. */ $pagination_args = array( 'base' => get_pagenum_link(1) . '%_%', 'format' => 'page/%#%', 'total' => $numpages, 'current' => $paged, 'show_all' => False, 'end_size' => 1, 'mid_size' => $pagerange, 'prev_next' => True, 'prev_text' => __(' 上一页'), 'next_text' => __('下一页 '), 'type' => 'plain', 'add_args' => false, 'add_fragment' => '' ); $paginate_links = paginate_links($pagination_args); if ($paginate_links) { echo "

"; } }

不是静态页面调用:

'post', //文章类型 'cat'=>218, //分类 'posts_per_page' => 40, //每页显示 'paged' => $paged //页码 ); $custom_query = new WP_Query( $custom_args ); ?> have_posts() ) : ?> have_posts() ) : $custom_query->the_post(); ?> max_num_pages,"",$paged); } ?>

当前分类未发现文章

调用指定分类下的文章2

3, //分类id 'posts_per_page' => 4, // 最多显示的文章数 ) ); if ( $the_query->have_posts() ) { // 获取分类目录名称 $category = get_the_category(); echo '
'.$category[0]->cat_name.'更多
'; while ( $the_query->have_posts() ) { $the_query->the_post(); ?>
>

post_content)), 0, 170,"..."); ?>
该分类没有文章'; } wp_reset_postdata(); ?>

调用指定自定义字段文章

'post', //文章类型 'meta_key' => 'wpb_post_views_count',//自定义字段名 'orderby' => 'meta_value_num', 'order' => 'DESC', 'posts_per_page' => 40, //每页显示 'paged' => $paged //页码 ); $custom_query = new WP_Query( $popularpost ); ?> have_posts() ) : ?> have_posts() ) : $custom_query->the_post(); ?> max_num_pages,"",$paged); } ?>

当前分类未发现文章

Worepress文章调用
Share this