1 | <?php
|
---|
2 |
|
---|
3 | include("settings.php");
|
---|
4 |
|
---|
5 | # WIDGET: Sidebar
|
---|
6 | if ( function_exists('register_sidebar') )
|
---|
7 | register_sidebar(array(
|
---|
8 | 'name' => 'Top Sidebar',
|
---|
9 | 'before_title' => '<h2>',
|
---|
10 | 'after_title' => '</h2>',
|
---|
11 | 'before_widget' => '<div class="box">',
|
---|
12 | 'after_widget' => '</div>',
|
---|
13 | ));
|
---|
14 |
|
---|
15 | # WIDGET: Content Bottom
|
---|
16 | if ( function_exists('register_sidebar') )
|
---|
17 | register_sidebar(array(
|
---|
18 | 'name' => 'Content Bottom',
|
---|
19 | 'before_title' => '<h2>',
|
---|
20 | 'after_title' => '</h2>',
|
---|
21 | 'before_widget' => '<div class="box">',
|
---|
22 | 'after_widget' => '</div>',
|
---|
23 | ));
|
---|
24 |
|
---|
25 | # Displays a list of pages
|
---|
26 | function dp_list_pages() {
|
---|
27 | global $wpdb;
|
---|
28 | $querystr = "SELECT $wpdb->posts.ID, $wpdb->posts.post_title FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' ORDER BY $wpdb->posts.post_title ASC";
|
---|
29 | $pageposts = $wpdb->get_results($querystr, OBJECT);
|
---|
30 | if ($pageposts) {
|
---|
31 | foreach ($pageposts as $post) {
|
---|
32 | ?><li><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></li><?php
|
---|
33 | }
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | # Displays a list of categories
|
---|
38 | function dp_list_categories($num=0, $exclude='') {
|
---|
39 | if (strlen($exclude)>0) $exclude = '&exclude=' . $exclude;
|
---|
40 | $categories = get_categories('hide_empty=1'.$exclude);
|
---|
41 | $first = true; $count = 0;
|
---|
42 | foreach ($categories as $category) {
|
---|
43 | if ($num>0) { $count++; if ($count>$num) break; } // limit
|
---|
44 | if ($category->parent<1) {
|
---|
45 | if ($first) { $first = false; $f = ' class="f"'; } else { $f = ''; }
|
---|
46 | ?><li<?php echo $f; ?>>
|
---|
47 | <a href="<?php echo get_category_link($category->cat_ID); ?>"><?php echo $category->name ?><?php echo $raquo; ?></a></li>
|
---|
48 | <?php
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | # Displays a list of popular posts
|
---|
54 | function dp_popular_posts($num, $pre='<li>', $suf='</li>', $excerpt=false) {
|
---|
55 | global $wpdb;
|
---|
56 | $querystr = "SELECT $wpdb->posts.post_title, $wpdb->posts.ID, $wpdb->posts.post_content FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ORDER BY $wpdb->posts.comment_count DESC LIMIT $num";
|
---|
57 | $myposts = $wpdb->get_results($querystr, OBJECT);
|
---|
58 | foreach($myposts as $post) {
|
---|
59 | echo $pre;
|
---|
60 | ?><a class="title" href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title ?></a><?php
|
---|
61 | if ($excerpt) {
|
---|
62 | dp_attachment_image($post->ID, 'medium', 'alt="'.$post->post_title.'"');
|
---|
63 | ?><p><?php echo dp_clean($post->post_content, 85); ?>... <a href="<?php echo get_permalink($post->ID); ?>">Read More</a></p><?php
|
---|
64 | }
|
---|
65 | echo $suf;
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | # Displays a list of recent categories
|
---|
70 | function dp_recent_comments($num, $pre='<li>', $suf='</li>') {
|
---|
71 | global $wpdb, $post;
|
---|
72 | $querystr = "SELECT $wpdb->comments.comment_ID, $wpdb->comments.comment_post_ID, $wpdb->comments.comment_author, $wpdb->comments.comment_content, $wpdb->comments.comment_author_email FROM $wpdb->comments WHERE $wpdb->comments.comment_approved=1 ORDER BY $wpdb->comments.comment_date DESC LIMIT $num";
|
---|
73 | $recentcomments = $wpdb->get_results($querystr, OBJECT);
|
---|
74 | foreach ($recentcomments as $rc) {
|
---|
75 | $post = get_post($rc->comment_post_ID);
|
---|
76 | echo $pre;
|
---|
77 | ?><strong><a href="<?php the_permalink() ?>#comment-<?php echo $rc->comment_ID ?>"><?php echo $rc->comment_author ?></a></strong> on <a href="<?php the_permalink() ?>#comment-<?php echo $rc->comment_ID ?>"><?php echo $post->post_title; ?></a><?php
|
---|
78 | echo $suf;
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | # Displays post image attachment (sizes: thumbnail, medium, full)
|
---|
84 | function dp_attachment_image($postid=0, $size='thumbnail', $attributes='') {
|
---|
85 | if ($postid<1) $postid = get_the_ID();
|
---|
86 | if ($images = get_children(array(
|
---|
87 | 'post_parent' => $postid,
|
---|
88 | 'post_type' => 'attachment',
|
---|
89 | 'numberposts' => 1,
|
---|
90 | 'post_mime_type' => 'image',)))
|
---|
91 | foreach($images as $image) {
|
---|
92 | $attachment=wp_get_attachment_image_src($image->ID, $size);
|
---|
93 | ?><img src="<?php echo $attachment[0]; ?>" <?php echo $attributes; ?> /><?php
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | # Removes tags and trailing dots from excerpt
|
---|
98 | function dp_clean($excerpt, $substr=0) {
|
---|
99 | $string = strip_tags(str_replace('[...]', '...', $excerpt));
|
---|
100 | if ($substr>0) {
|
---|
101 | $string = substr($string, 0, $substr);
|
---|
102 | }
|
---|
103 | return $string;
|
---|
104 | }
|
---|
105 |
|
---|
106 | # Displays the comment authors gravatar if available
|
---|
107 | function dp_gravatar($size=50, $attributes='', $author_email='') {
|
---|
108 | global $comment, $settings;
|
---|
109 | if (dp_settings('gravatar')=='enabled') {
|
---|
110 | if (empty($author_email)) {
|
---|
111 | ob_start();
|
---|
112 | comment_author_email();
|
---|
113 | $author_email = ob_get_clean();
|
---|
114 | }
|
---|
115 | $gravatar_url = 'http://www.gravatar.com/avatar/' . md5(strtolower($author_email)) . '?s=' . $size . '&d=' . dp_settings('gravatar_fallback');
|
---|
116 | ?><img src="<?php echo $gravatar_url; ?>" <?php echo $attributes ?>/><?php
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | # Retrieves the setting's value depending on 'key'.
|
---|
121 | function dp_settings($key) {
|
---|
122 | global $settings;
|
---|
123 | return $settings[$key];
|
---|
124 | }
|
---|
125 |
|
---|
126 | ?>
|
---|