Created
August 6, 2012 04:04
-
-
Save joshferrara/3270107 to your computer and use it in GitHub Desktop.
Wordpress Random Comment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setup everything | |
<?php | |
function get_random_comment($ID = 0) { | |
if( $ID == 0 ) { | |
global $post; | |
$ID = $post->ID; | |
} | |
global $wpdb; | |
return $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' AND comment_ID > 9 ORDER BY RAND() LIMIT 1", $ID)); | |
} | |
function setup_random_comment($ID = 0) { | |
global $comment; | |
$comment = get_random_comment($ID); | |
} | |
?> | |
// display comments | |
<?php | |
query_posts('page_id=231'); | |
if (have_posts()) : while (have_posts()) : the_post(); | |
setup_random_comment(); | |
?> | |
<p> | |
<?php comment_text_rss(); ?> | |
</p> | |
<?php endwhile; endif; wp_reset_query(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment