想要在首页调用wordpress某个栏目的内容,可以按照分类ID来调用,调用出来的内容一般有:调用栏目最新内容、调用栏目推荐内容、调用栏目随机内容这三种形式。简站wordpress小编在此为大家放出三种不同方式调用的代码如下:
通过指定分类目录ID调用该目录下的最新内容
说明:category=4为分类目录ID numberposts=6为要显示数量
通过指定分类目录ID调用该目录下的推荐内容
6, 'cat' => 4, 'post__in' => get_option( 'sticky_posts' ) );//wodepress.com $sticky_posts = new WP_Query( $args ); while ( $sticky_posts->have_posts() ) : $sticky_posts->the_post();?>
说明:posts_per_page 6为要显示的数量 cat 4 为要调用的分类目录ID
通过指定分类目录ID调用该目录下的随机内容
$category){ $catid = $category->term_id; } $args = array('orderby' => 'rand','showposts' => 6,'cat' => 4 ); $query_posts = new WP_Query();//wodepress.com $query_posts->query($args); while ($query_posts->have_posts()) : $query_posts->the_post(); ?>
说明:showposts 6为要显示的数量 cat 4为要调用的分类目录的ID
原文
https://www.jianzhanpress.com/?p=7223
上一篇:数据治理,管什么?