/
plugin.php
102 lines (99 loc) · 3.49 KB
/
plugin.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
Plugin Name: Advance Widget Pack
Plugin URI: http://www.github.com/saumya010/advance-widget-pack/
Description: A plugin to display author bio, author list, popular post, featured posts, recent posts and recent comments.
Version: 1.0.2
Author: Saumya Sharma, Purva Jain, Nidarshana Sharma, Nikita Pariyani, Shruti Taldar
Author URI: http://github.com/saumya010
License: GPL2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
?>
<?php
function awp_stylesheet()
{
wp_register_style( 'my-plugin', plugins_url('style.css', __FILE__) );
wp_enqueue_style( 'my-plugin',plugins_url('style.css', __FILE__) );
}
add_action('wp_enqueue_scripts', 'awp_stylesheet');
add_action('wp_head', 'awp_add_view');
function awp_get_author_list($noauth,$exc){
echo "<ul>";
wp_list_authors(array('number'=>$noauth,'exclude'=>$exc));
echo "</ul>";
}
function awp_display_featured_image(){
global $post;
$post_id=$post->ID;
if ( has_post_thumbnail($post_id) ) {
the_post_thumbnail('featured-thumb');
}
}
function awp_display_post_author_name(){
global $post;
$author_id= $post->post_author;
echo get_the_author_meta('first_name',$author_id);
echo " ";
echo get_the_author_meta('last_name',$author_id);
}
function awp_display_author_description($post_id=0){
$post = get_post( $post_id );
$auth_id=$post->post_author;
echo get_the_author_meta( 'description', $auth_id);
}
function awp_add_view(){
if(is_single()){
global $post;
$current_views=get_post_meta($post->ID, "wp_views", true);
if(!isset($current_views) OR empty($current_views) OR !is_numeric($current_views) ) {
$current_views = 0;
}
$new_views = $current_views + 1;
update_post_meta($post->ID, "wp_views", $new_views);
return $new_views;
}
}
function awp_get_view_count() {
global $post;
$current_views = get_post_meta($post->ID, "wp_views", true);
if(!isset($current_views) OR empty($current_views) OR !is_numeric($current_views) ) {
$current_views = 0;
}
return $current_views;
}
function awp_show_views($singular = "view", $plural = "views", $before = "This post has: ") {
global $post;
$current_views = get_post_meta($post->ID, "wp_views", true);
$views_text = $before . $current_views . " ";
if ($current_views == 1) {
$views_text .= $singular;
}
else {
$views_text .= $plural;
}
echo $views_text;
}
function custom_excerpt_length( $length ) {
return 15;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
function new_excerpt_more($more) {
global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read More..</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
include 'feature_posts.php';
include 'popular-post-stat-widget.php';
include 'recent_posts.php';
include 'recents.php';
include 'random-post.php';
include 'author_list.php';
include 'author_bio_widget.php';
add_action('widgets_init',create_function('', 'return register_widget("Recent_Comments");'));
add_action('widgets_init',create_function('', 'return register_widget("Featured_Posts");'));
add_action('widgets_init',create_function('', 'return register_widget("Post_Stats_Counter");'));
add_action('widgets_init',create_function('', 'return register_widget("awp_recent_posts");'));
add_action('widgets_init',create_function('', 'return register_widget("awp_random_posts");'));
add_action('widgets_init',create_function('', 'return register_widget("Author_List");'));
add_action('widgets_init',create_function('', 'return register_widget("Author_Bio");'));