1
当前使用ACF Repeater for WP来显示某个类别中的某些帖子,但是如果我添加了同一个中继器,我希望它保留一个日志,记录已经使用后的id,因此它可以排除他们从新的循环。忽略已在循环中使用的wordpress中的帖子
唯一的问题是我当前的代码对于第一个循环和第二个循环都正常工作,但是添加的不止两个只是重置回第一组职位。转储数组看起来好像不会将数组添加到数组中。
第一阵列看起来像这样
array(3) { [0]=> int(28890) [1]=> int(28790) [2]=> int(28785) }
二阵列
array(3) { [0]=> int(28749) [1]=> int(1) [2]=> int(28484) }
三
array(3) { [0]=> int(28890) [1]=> int(28790) [2]=> int(28785) }
这里是我的代码
<?php
$cat = get_sub_field('category_name');
$args = array(
'posts_per_page' => 3,
'category_name' => $cat,
'post__not_in' => $ids
);
query_posts($args);
$ids = array();
?>
<div class="hub-cont">
<?php while (have_posts()) : the_post(); ?>
<?php array_push($ids,get_the_ID()); /*$ids[] = get_the_ID();*/?>
<div class="blockitem2 small-12 medium-4 large-4">
<?php
// Fetch all posts relating to a certain tag then display 4 of them
//Get the Thumbnail URL
$src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(720,405), false, '');
?>
<div id="promolink"></div><div class="blockimage" style="background-image: url('<?php echo $src[0]; ?>'); background-repeat: no-repeat; background-size: cover;">
<div class="cats"><?php echo the_category(' '); ?></div>
</div>
<div class="meta">
<a class="gdbnewslink dark" href="<?php echo get_permalink();?>" ><?php the_title();?> </a>
</div>
<div class="clear"></div>
<div id="newsintro"><?php $text = $post->post_content; $trimmed = wp_trim_words($text, 50, null); echo $trimmed; ?></div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php var_dump($ids); ?>
</div>
阵列对我来说仍然很新,所以您的指导将非常感谢!
新回路从哪里开始?新循环是否调用完全相同的代码,那么它将不起作用,因为您将'$ ids'重置为空数组。 – Luceos
是的,循环再次是相同的代码。我认为这是重置数组,我怎么能够创建可重复的代码,而不重置数组? – Kyon147