-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
29 lines (29 loc) · 741 Bytes
/
functions.php
File metadata and controls
29 lines (29 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
/**
* Display a list of random posts
* on single post page in WordPress
* @param int $post_count
* @return string $data
*/
function get_random_posts($post_count) {
if (is_numeric($post_count)) {
global $post;
// variable for string
$data = '';
// arguments
$args = array(
'post_type' => 'post',
'posts_per_page' => $post_count,
'orderby' => 'rand'
);
// query posts
$random_posts = get_posts($args);
$data = '<ul>';
foreach ($random_posts as $post) {
$data .= '<li><a href="'.get_the_permalink().'">'.get_the_title().'</a></li>';
}
$data .= '</ul>';
return $data;
}
}
?>