-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
85 lines (69 loc) · 3.05 KB
/
functions.php
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* Sage includes
*
* The $sage_includes array determines the code library included in your theme.
* Add or remove files to the array as needed. Supports child theme overrides.
*
* Please note that missing files will produce a fatal error.
*
* @link https://github.com/roots/sage/pull/1042
*/
$sage_includes = [
'lib/assets.php', // Scripts and stylesheets
'lib/extras.php', // Custom functions
'lib/setup.php', // Theme setup
'lib/titles.php', // Page titles
'lib/wrapper.php', // Theme wrapper class
'lib/customizer.php', // Theme customizer
];
foreach ( $sage_includes as $file ) {
if ( ! $filepath = locate_template( $file ) ) {
trigger_error( sprintf( __( 'Error locating %s for inclusion', 'devanagari' ), $file ), E_USER_ERROR );
}
require_once $filepath;
}
unset( $file, $filepath );
// POPULAR POST WIDGET
class show_popular extends WP_Widget {
function show_popular() {
$widget_ops = array( 'classname' => 'show_popular', 'description' => __( 'Show your popular posts.' ) );
$this->WP_Widget( 'show_popular', __( 'Popular Posts' ), $widget_ops, $control_ops );
}
function widget( $args, $instance ) {
extract( $args );
// $options = get_option('custom_recent');
$title = $instance['title'];
$postscount = $instance['posts'];
$myposts = get_posts( array( 'orderby' => 'comment_count', 'numberposts' => $postscount ) );
echo $before_widget . $before_title . $title . $after_title;
// SHOW the posts
?><ul><?php
foreach ( $myposts as $k => $post ) {
$id = $post->ID;
$author_id = $post->post_author;
$author_name = get_the_author_meta( 'display_name', $author_id );
?>
<li>
<button class="button button--circle"><span class="list-index"><?php echo ++$k; ?></span></button>
<a href="<?php the_permalink( $id ); ?>" class="post-title"><?php echo get_the_title( $id ); ?></a>
<a href="<?php echo get_author_posts_url( $author_id ); ?>" class="author-link"><?php echo $author_name; ?></a>
</li>
<?php
}
?></ul><?php
echo $after_widget;
}
function update( $newInstance, $oldInstance ) {
$instance = $oldInstance;
$instance['title'] = strip_tags( $newInstance['title'] );
$instance['posts'] = $newInstance['posts'];
return $instance;
}
function form( $instance ) {
echo '<p style="text-align:right;"><label for="' . $this->get_field_id( 'title' ) . '">' . __( 'Title:' ) . ' <input style="width: 200px;" id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . $instance['title'] . '" /></label></p>';
echo '<p style="text-align:right;"><label for="' . $this->get_field_id( 'posts' ) . '">' . __( 'Number of Posts:', 'widgets' ) . ' <input style="width: 50px;" id="' . $this->get_field_id( 'posts' ) . '" name="' . $this->get_field_name( 'posts' ) . '" type="text" value="' . $instance['posts'] . '" /></label></p>';
echo '<input type="hidden" id="custom_recent" name="custom_recent" value="1" />';
}
}
add_action( 'widgets_init', create_function( '', 'return register_widget("show_popular");' ) );