1
|
1 |
<?php |
|
2 |
class ocmx_comment_widget extends WP_Widget { |
|
3 |
/** constructor */ |
|
4 |
function ocmx_comment_widget() { |
|
5 |
parent::WP_Widget(false, $name = "OCMX Latest Comments", array("description" => "Display the Latest Comments")); |
|
6 |
} |
|
7 |
|
|
8 |
/** @see WP_Widget::widget */ |
|
9 |
function widget($args, $instance) { |
|
10 |
extract( $args ); |
|
11 |
global $wpdb; |
|
12 |
$comment_count = esc_attr($instance["comment_count"]); |
|
13 |
$latest_comments = $wpdb->get_results($wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_approved = 1 ORDER BY comment_date DESC LIMIT ".$comment_count, "ARRAY_A") ); |
|
14 |
?> |
|
15 |
<li class="widget recent-comments"> |
|
16 |
<div class="container-header-dark-normal"><span></span></div> |
|
17 |
<ul class="container-dark"> |
|
18 |
<?php foreach($latest_comments as $latest_comment) : |
|
19 |
$this_comment = get_comment($latest_comment->comment_ID); |
|
20 |
$use_id = $this_comment->comment_post_ID; |
|
21 |
$this_post = get_post($use_id); |
|
22 |
$post_title = $this_post->post_title; |
|
23 |
$post_link = get_permalink($post->ID); |
|
24 |
?> |
|
25 |
<li class="clearfix"> |
|
26 |
<a href="<?php echo get_comment_link($latest_comment->comment_ID); ?>" class="detail-image"><?php echo get_avatar($this_comment, 40 ); ?></a> |
|
27 |
<a href="<?php echo get_comment_link($latest_comment->comment_ID); ?>" class="detail-link"> |
|
28 |
<span class="date"><?php echo date('F d Y', strtotime($latest_comment->comment_date)); ?> <?php echo date("H\:i a", strtotime($latest_comment->comment_date)); ?></span> |
|
29 |
<?php echo $post_title; ?> |
|
30 |
</a> |
|
31 |
</li> |
|
32 |
<?php endforeach; ?> |
|
33 |
</ul> |
|
34 |
<div class="container-footer-dark-normal"><span></span></div> |
|
35 |
</li> |
|
36 |
<?php |
|
37 |
} |
|
38 |
|
|
39 |
/** @see WP_Widget::update */ |
|
40 |
function update($new_instance, $old_instance) { |
|
41 |
return $new_instance; |
|
42 |
} |
|
43 |
|
|
44 |
/** @see WP_Widget::form */ |
|
45 |
function form($instance) { |
|
46 |
$comment_count = esc_attr($instance["comment_count"]); |
|
47 |
|
|
48 |
?> |
|
49 |
<p> |
|
50 |
<label for="<?php echo $this->get_field_id('comment_count'); ?>">Comment Count</label> |
|
51 |
<select size="1" class="widefat" id="<?php echo $this->get_field_id('comment_count'); ?>" name="<?php echo $this->get_field_name('comment_count'); ?>"> |
|
52 |
<?php for($i = 1; $i < 10; $i++) : ?> |
|
53 |
<option <?php if($comment_count == $i) : ?>selected="selected"<?php endif; ?> value="<?php echo $i; ?>"><?php echo $i; ?></option> |
|
54 |
<?php endfor; ?> |
|
55 |
</select> |
|
56 |
</p> |
|
57 |
<?php |
|
58 |
} // form |
|
59 |
|
|
60 |
}// class |
|
61 |
|
|
62 |
//This sample widget can then be registered in the widgets_init hook: |
|
63 |
|
|
64 |
// register FooWidget widget |
|
65 |
add_action('widgets_init', create_function('', 'return register_widget("ocmx_comment_widget");')); |
|
66 |
|
|
67 |
?> |