Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $cat_args = array(
- 'orderby' => 'name',
- 'order' => 'ASC',
- 'child_of' => 0
- );
- $categories=get_categories($cat_args);
- $rand_keys = array_rand($categories, 5); // 5 is the number of categories you want
- foreach ($rand_keys as $key) {
- $post_args = array(
- 'numberposts' => 1,
- 'category' => $categories[$key]->term_id
- );
- $posts = get_posts($post_args);
- foreach($posts as $post) {
- ?>
- content here....
- <?php
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment