Guest User

Untitled

a guest
Feb 20th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <?php function list_articles(){
  2. global $month, $wpdb, $wp_version;
  3. $now = current_time('mysql');
  4.  
  5. if(version_compare($wp_version, '2.1', '<')){$current_posts = "post_date < '$now'";} else {$current_posts = "post_type='post'";}
  6. $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");
  7.  
  8. if($arcresults){
  9. foreach($arcresults as $arcresult) {
  10. $url = get_month_link($arcresult->year, $arcresult->month);
  11. $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
  12. echo get_archives_link($url, $text, '','<strong>','</strong>');
  13.  
  14. $thismonth = zeroise($arcresult->month,2);
  15. $thisyear = $arcresult->year;
  16.  
  17. $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");
  18.  
  19. if ($arcresults2) {
  20. echo "<ul class=\"articles_list\">\n";
  21. foreach ($arcresults2 as $arcresult2) {
  22. if ($arcresult2->post_date != '0000-00-00 00:00:00') {
  23. $url = get_permalink($arcresult2->ID);
  24. $arc_title = $arcresult2->post_title;
  25.  
  26. if ($arc_title) $text = strip_tags($arc_title);
  27. else $text = $arcresult2->ID;
  28. $title_text = wp_specialchars($text, 1);
  29.  
  30. echo '<li>' . mysql2date('d', $arcresult2->post_date). ': ' . "<a href='$url' title='$title_text'>".wptexturize($text)."</a>";
  31.  
  32. $comments_count = $wpdb->get_var("SELECT COUNT(comment_id) FROM " . $wpdb->comments . " WHERE comment_post_ID=" . $arcresult2->ID . " AND comment_approved='1'");
  33. if ($arcresult2->comment_status == "open" OR $comments_count > 0) echo ' (' . $comments_count . ')';
  34. echo '</li>';
  35. }
  36. }
  37. echo '</ul>';
  38. }
  39. }
  40. }
  41. }?>
Add Comment
Please, Sign In to add comment