%title% %post% %more% (%commentcount%)', 'Format to use when displaying options.');
add_option('miniposts_date_format', 'Y/n/j', 'Date format.');
add_option('miniposts_more_text', 'More...', 'Text to display in place of "%more" when displaying multipart asides.');
add_option('miniposts_title', 'Miniposts 0.6.4', 'The title to display at the top of the minipost widget.');
add_option('miniposts_maximum', '0', 'The maximum number of miniposts to display. 0 is infinite.');
// Auto-install: If there are no previous meta values for '_mini_post', automatically add one for each post
if (0 == $wpdb->get_var("SELECT count(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_mini_post'")) {
if ($posts = $wpdb->get_results("SELECT * FROM $wpdb->posts")) {
foreach ($posts as $post) {
add_post_meta($post->ID, '_mini_post', '0');
}
}
}
/** Get the number of comments associted with the named post. Originally
* written by Mountain Dew Virus:
* http://dev.wp-plugins.org/file/comment-count/trunk/comment-count.php
*
* Heavily modified from the original.
*/
function miniposts_get_comment_count($post) {
global $wpdb;
$request = "SELECT COUNT(*) FROM $wpdb->comments WHERE
comment_post_ID='" . $wpdb->escape($post) . "' AND "
. " comment_approved='1'";
return $wpdb->get_var($request);
}
function is_mini_post() {
global $post;
return (bool) get_post_meta($post->ID, '_mini_post', true);
}
/**
* Return the text to display for a minipost. The preferred order is:
*
* post_excerpt - If the post has an excerpt, this is returned.
* post_content, before first <!--more--> - The text of the
* post before the first more tag appears.
* post_content- The text of the post.
*
*
* @param $minipost An object containing the fields 'post_content' (the
* text of the post) and 'post_excerpt' (the excerpt of
* the post).
*
* @returns An array with the text of the post, and a boolean indicating
* if there is more to the post.
*/
function miniposts_get_text(&$minipost) {
// See if we have a post excerpt
if (!is_null($minipost->post_excerpt)
&& strlen($minipost->post_excerpt) > 0
&& strlen(trim($minipost->post_excerpt)) > 0
) {
return array($minipost->post_excerpt,true);
}
// See if we have a tag
if (preg_match('/(.*)/s', $minipost->post_content, $matches)) {
return array($matches[1], true);
}
return array($minipost->post_content, false);
}
function get_mini_posts(
$format = null,
$limit = null
) {
global $wpdb;
if (is_null($limit)) {
$limit = get_option('miniposts_maximum');
}
if (0 != (int)$limit ) {
$limit = (int) $limit;
$limit = ' LIMIT '.$limit;
}
else {
$limit = '';
}
$now = current_time('mysql');
if ($miniposts = $wpdb->get_results("SELECT ID, post_date, UNIX_TIMESTAMP(post_date) AS post_date_unix, post_content, post_excerpt, post_title FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE post_date < '$now' AND post_status = 'publish' AND $wpdb->postmeta.meta_key = '_mini_post' AND $wpdb->postmeta.meta_value = '1' ORDER BY post_date DESC" . $limit)) {
if (is_null($format)) {
$format = get_option("miniposts_format");
}
$dateFormat = get_option("miniposts_date_format");
$moreText = get_option("miniposts_more_text");
echo '