/wp-content/themes/transparency/functions.php

https://github.com/Canuckaholic/Pop-Digital · PHP · 142 lines · 117 code · 14 blank · 11 comment · 11 complexity · 14eec8ecdc859fd22edb683830162119 MD5 · raw file

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