我增加了一个acf图片库的存档条款,我想采取这些图像,并插入一个图片从画廊每3个帖子在这个术语存档。这是我到目前为止的情况,但我还没有让他们按顺序分发每3个帖子。
1-2-3张贴图片1 4-5-6张贴图片2 7-8-9张贴图片3
// get the current taxonomy term
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$images = get_field('term_gallery', $taxonomy .'_' . $term_id); //image ids
$size = 'full'; // (thumbnail, medium, large, full or custom size)
$counter = 1;
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', get_post_type() );
?>与以上的整个画廊是显示每3个帖子。如图所示
1-2-3张贴图像1+图像2+图像3 4-5-6张贴图像1+图像2+图像3
UPDATE不知道我是怎么得到这个的,但是它部分地工作了,只是第一页之后的分页不起作用吗?没有任何图片在下一页显示,当我期望得到下3张图片的画廊。
// get the current taxonomy term
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$images = get_field('term_gallery', $taxonomy .'_' . $term_id);
$size = 'full'; // (thumbnail, medium, large, full or custom size)
$images_len = count($images); // max
$counter = 1;
$img_ct = 0;
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', get_post_type() );
?>发布于 2019-11-11 11:42:26
我找到了一个类似的解决方案
// get the current taxonomy term
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$images = get_field('term_gallery', $taxonomy .'_' . $term_id);
$size = 'full'; // (thumbnail, medium, large, full or custom size)
$limit = 3; //how many gallery images per page
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$offset = ($paged - 1) * $limit;
$images = array_slice($images, $offset, $limit);
$counter = 1; //post counter
$img_ct = 0; //image counter
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', get_post_type() );
?>发布于 2019-11-11 01:36:09
正如我在评论中所指出的,例如,如果您每页显示9篇文章,这意味着每页将显示3幅图片库图像,并且希望第1页显示图像1-3,第2页显示图像4-6,等等,那么您需要对图片库图像进行分页:
// the number 3 below is the position where the image is to be added to
$paged = max( 1, get_query_var( 'paged' ) ); // get the current page number
$per_page = floor( max( 1, get_query_var( 'posts_per_page' ) ) / 3 );
$counter = 1;
$img_ct = ( $paged - 1 ) * $per_page; // start showing images of this index这将取代这一部分:
$counter = 1;
$img_ct = 0;另外,您应该使用if ( ! empty( $images ) ),而不是只使用if ( $images )。
https://wordpress.stackexchange.com/questions/352198
复制相似问题