Last active
January 3, 2016 23:39
-
-
Save edtoken/8536082 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Функция вывода постов по месяцу. | |
---------- | |
* Параметры: | |
* $show_comment_count(0) - показывать ли колличество комментариев. 1 - показывать. | |
* $before ('<h4>') - HTML тег до заголовка (названия месяца). | |
* $after ('</h4>') - HTML тег после заголовка. | |
* $year (0) - огриничить вывод годом. Если указать 2009, будут выведены записи за 2009 год по месяцам | |
* $post_type ('post') - тип поста. Если нужно вывести нестандартный тип постов (отличный от post) | |
* $limit(100) - ограничение количества выводиммых постов для каждого месяца. При большой базе, создается сильная нагрузка. Укажите 0 если нужно снять ограничение | |
---------- | |
Пример вызова: <php echo get_blix_archive(1, '<h4>', '</h4>'); ?> | |
*/ | |
function get_blix_archive($show_comment_count=0, $before='<h4>', $after='</h4>', $year=0, $post_type='post', $limit=100){ | |
global $month, $wpdb; | |
$result = ''; | |
if($year) $AND_year = " AND YEAR(post_date)='$year'"; | |
if($limit) $LIMIT = " LIMIT $limit"; | |
$arcresults = $wpdb->get_results(" | |
SELECT | |
DISTINCT YEAR(post_date) AS year, | |
MONTH(post_date) AS month, | |
count(ID) as posts | |
FROM " . $wpdb->posts . " | |
LEFT JOIN wp_term_relationships as wt | |
ON wt.object_id = ID | |
WHERE | |
post_type='$post_type' | |
AND wt.term_taxonomy_id='3' | |
$AND_year | |
AND post_status='publish' | |
GROUP BY YEAR(post_date), MONTH(post_date) | |
ORDER BY post_date DESC | |
"); | |
if($arcresults){ | |
foreach($arcresults as $arcresult){ | |
$url = get_month_link($arcresult->year, $arcresult->month); | |
$text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year); | |
$result .= get_archives_link($url, $text, '', $before, $after); | |
$thismonth = zeroise($arcresult->month,2); | |
$thisyear = $arcresult->year; | |
// $arcresults2 = $wpdb->get_results("SELECT ID, post_date, post_title, comment_status, guid, comment_count FROM " . $wpdb->posts . " WHERE post_date LIKE '$thisyear-$thismonth-%' AND post_status='publish' AND post_type='$post_type' AND post_password='' ORDER BY post_date DESC $LIMIT"); | |
// if ($arcresults2){ | |
// $result .= "<ul class=\"postspermonth\">\n"; | |
// foreach ($arcresults2 as $arcresult2) { | |
// if ($arcresult2->post_date != '0000-00-00 00:00:00') { | |
// $url = get_permalink($arcresult2->ID); //$arcresult2->guid; | |
// $arc_title = $arcresult2->post_title; | |
// if ($arc_title) $text = strip_tags($arc_title); | |
// else $text = $arcresult2->ID; | |
// $result .= "<li>". get_archives_link($url, $text, ''); | |
// if($show_comment_count){ | |
// $cc = $arcresult2->comment_count; | |
// if ($arcresult2->comment_status == "open" OR $comments_count > 0) $result .= " ($cc)"; | |
// } | |
// $result .= "</li>\n"; | |
// } | |
// } | |
// $result .= "</ul>\n"; | |
// } | |
} | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment