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?

    1 answer 1

    Thank you all, the problem is solved, it was necessary to add a couple of lines of code. A working script, maybe someone will need:

     $counter = 0; $index = 0; foreach (array_chunk($categories, 2) as $cat_block) { $counter++; if ($counter %5 == 0) { $title = $game_query[$index]->post_title; $index++; ?> <div class="rand_game"> <?php echo $title;?> </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 } ?> 
    • Something terrible you do there. - Shadow33
    • The task was this, you need to display a list of all categories of 2 categories in the div 'cat_block', every 5 '. Cat_block' you need to display a div. '.rand_game' with one post. An example of how it looks can be viewed onlineguru.ru , only there is not every 5, but the scheme is clear. I am not a professional in php, wrote as I could) If you can give a couple of tips on how to improve this script, I will be very happy, thank you. - skit008