Рандомный пост из категории.
24.05.10 / Категории Uncategorized | Оставить комментарийЭто кусок кода, который выводит рандомный пост из некоторой категории.
<?php $catID = 5; $customPostQuery = new WP_query(); $customPosts = $customPostQuery->query("cat=$catID"); if ($customPosts) : while ($customPosts = $customPostQuery->have_posts()) : $customPosts = $customPostQuery->the_post(); ?> <?php $wordings[] = $post->ID; ?> <?php endwhile; endif; if(isset($wordings)&&$wordings) { $c = count($wordings)-1; $r = $wordings[rand(0, $c)]; $pq = new WP_Query(); $pq->query("p=$r"); if($pq) { $pq->have_posts(); $pq->the_post(); the_content(); edit_post_link('Edit Block', '<p class="editBoxy">', '</p>'); } } ?>
Вы можете сослаться на эту статью:
http://www.rantiev.com/random-post/trackback/