There are 2 arrays
$categories = get_categories($args); $game_query = get_posts($post_args); $ categories - a list of categories
$ game_query - list of posts
There is such a cycle that displays categories and every 5 blocks with categories inserts a div "rand_game"
$counter = 0; foreach (array_chunk($categories, 2) as $cat_block) { $counter++; if ($counter %5 == 0) { ?> <div class="rand_game"> </div> <?php } ?> <div class="cat_block"> <?php foreach ($cat_block as $cat_item) { ?> <div class="cat_item"> <div class="category_text"> <p><?php echo $cat_item->name; ?></p> </div> </div> <?php } ?> </div> <?php } So, in the "rand_game" div it is necessary to deduce values from an array with a list of posts, for example, to deduce post_title. How to do it?