我正在创建一个Wordpress页面,其中团队子类别中的所有帖子都显示在网格中。我用下面的代码得到了这个。格式和总体布局很好,但它只显示子类别中最近的5篇文章,而不是所有文章。在我的Wordpress帐户中,我有7篇应该显示的帖子。我应该如何检索帖子,使其全部显示出来。
<ul class="faces">
<?php
$categories = get_categories( \'child_of=2\' );
foreach ( $categories as $category ) {
echo \'<div class="grid-row"><h2>\'.$category->name.\'</h2></div>\';
$cat_posts = get_posts( \'cat=\'.$category->term_id );
$end = count( $cat_posts ) - 1;
$i = 0;
foreach ( $cat_posts as $post ) {
setup_postdata( $post );
$face = get_field( \'face\' );
$name = get_field( \'fullname\' );
if ( $i % 6 === 0 ) {
echo \'<div class="grid-row">\';
}
echo \'<div class="obj">\';
echo wp_get_attachment_image($face)
. \'<div class="name">\'.$name.\'</div>\';
echo \'</div>\';
if ( $i % 6 === 5 ) {
echo \'</div>\';
}
$i++;
}
}?>
</ul>
//css
div.grid-row {
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
}
div.obj{
float: left;
position: relative;
padding-right: 10px;
}
.faces{
width: 1000px;
}
修订如下:
以下职位版次:
<?php
$categories = get_categories( \'child_of=2\' );
foreach ( $categories as $category ) {
echo \'<div class="grid-row"><h2>\'.$category->name.\'</h2></div>\';
$args1 = array( \'posts_per_page\' => -1, \'cat=\'.$category->term_id );
$cat_posts = get_posts( $args1 );
$end = count( $cat_posts ) - 1;
$i = 0;
foreach ( $cat_posts as $post ) {
$post_category = get_the_category($post->ID);
if($post_category->cat_name == $category->name){
setup_postdata( $post );
$face = get_field( \'face\' );
$name = get_field( \'fullname\' );
if ( $i % 6 === 0 ) {
echo \'<div class="grid-row">\';
}
echo \'<div class="obj">\';
echo \'<div class="faceThumb">\';
echo wp_get_attachment_image($face);
echo \'</div>\';
echo \'<div class="name">\';
echo $name;
echo \'</div>\';
echo \'</div>\';
if ( $i % 6 === 5 ) {
echo \'</div>\';
}
}
$i++;
}
}?>