Advertisement
Guest User

Untitled

a guest
Feb 21st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: WP-Archives
  4. Plugin URI: http://blog.unijimpe.net/
  5. Description: Display your archives with year/month list.
  6. Version: 0.8
  7. Author: Jim Penaloza Calixto
  8. Author URI: http://blog.unijimpe.net
  9. */
  10. function wparc_getarchives() {
  11. global $month, $wpdb, $wp_version;
  12. $now = current_time('mysql');
  13.  
  14. if (version_compare($wp_version, '2.1', '<')) {
  15. $current_posts = "post_date < '$now'";
  16. } else {
  17. $current_posts = "post_type='post'";
  18. }
  19. $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, count(ID) as posts FROM " . $wpdb->posts . " WHERE post_status='publish' AND $current_posts AND post_password='' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC");
  20.  
  21. if ($arcresults) {
  22. foreach ($arcresults as $arcresult) {
  23. $url = get_month_link($arcresult->year, $arcresult->month);
  24. $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
  25.  
  26.  
  27.  
  28. $thismonth = zeroise($arcresult->month,2);
  29. $thisyear = $arcresult->year;
  30.  
  31. $arcresults2 = $wpdb->get_results("SELECT ID, post_date, post_title, comment_status FROM " . $wpdb-> posts . " WHERE post_date LIKE '$thisyear-$thismonth-%' AND $current_posts AND post_status='publish' AND post_password='' ORDER BY post_date DESC");
  32.  
  33. if ($arcresults2) {
  34. echo "<div class='list'><ul>\n";
  35. foreach ($arcresults2 as $arcresult2) {
  36. if ($arcresult2->post_date != '0000-00-00 00:00:00') {
  37. $url = get_permalink($arcresult2->ID);
  38. $arc_title = $arcresult2->post_title;
  39.  
  40. if ($arc_title) {
  41. $text = strip_tags($arc_title);
  42. } else {
  43. $text = $arcresult2->ID;
  44. }
  45. $title_text = wp_specialchars($text, 1);
  46. echo "<li class='list'><a href=\"" . $url . "\" title=\"" . $title_text . "\">" . wptexturize($text) . "</a></li>\n";
  47. }
  48. }
  49. echo "</ul></div>\n";
  50. }
  51.  
  52. }
  53. }
  54. }
  55.  
  56. function wparc_setarchive() {
  57. add_filter('the_content', 'wparc_findarchives');
  58. }
  59.  
  60. function wparc_findarchives($post) {
  61. if (substr_count($post, '<!--wp_archives-->') > 0) {
  62. $archives = wparc_getarchives();
  63. $post = str_replace('<!--wp_archives-->', $archives, $post);
  64. }
  65. return $post;
  66. }
  67. function wparc_addheader() {
  68. echo "<!-- WP-Archives 0.8 by unijimpe -->\n";
  69. }
  70. add_action('init', 'wparc_setarchive');
  71. add_action('wp_head', 'wparc_addheader');
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement