Latest Post From Each Category');
add_option('ddle_sort', 'cata');
add_option('ddle_cat_links', TRUE);
add_option('ddle_hide_protected', TRUE);
add_option('ddle_show_date', TRUE);
add_option('ddle_date_format', 'F jS, Y');
add_option('ddle_excerpts', FALSE);
add_option('ddle_chars', 200);
add_option('ddle_comment_link', FALSE);
add_option('ddle_comment_num', FALSE);
add_option('ddle_comments_none', FALSE);
add_option('ddle_limit', 0);
add_option('mattc_categoryname', TRUE);
add_option('mattc_removeduplicates', TRUE);
function ddle_add_option_pages() {if (function_exists('add_options_page')) {add_options_page('Latest From Each Category', 'DDLatestFromEach', 8, __FILE__, 'ddle_options_page');}}
function ddle_options_page() {
global $ddle_version;
if (isset($_POST['set_defaults'])) {
echo '
';
update_option('ddle_header', 'Latest Post From Each Category
');
update_option('ddle_sort', 'cata');
update_option('ddle_cat_links', TRUE);
update_option('ddle_hide_protected', TRUE);
update_option('ddle_show_date', TRUE);
update_option('ddle_date_format', 'F jS, Y');
update_option('ddle_excerpts', FALSE);
update_option('ddle_chars', 200);
update_option('ddle_comment_link', FALSE);
update_option('ddle_comment_num', FALSE);
update_option('ddle_comments_none', FALSE);
update_option('ddle_limit', 0);
update_option('mattc_categoryname', TRUE);
update_option('mattc_removeduplicates', TRUE);
echo 'Default Options Loaded!';
echo '
';
} else if (isset($_POST['info_update'])) {
echo '';
update_option('ddle_header', (string) $_POST["ddle_header"]);
update_option('ddle_sort', (string) $_POST["ddle_sort"]);
update_option('ddle_cat_links', (string) $_POST["ddle_cat_links"]);
update_option('ddle_hide_protected', (bool)$_POST["ddle_hide_protected"]);
update_option('ddle_show_date', (bool) $_POST["ddle_show_date"]);
update_option('ddle_date_format', (string) $_POST["ddle_date_format"]);
update_option('ddle_excerpts', (bool) $_POST["ddle_excerpts"]);
update_option('ddle_chars', (string) $_POST["ddle_chars"]);
update_option('ddle_comment_link', (bool) $_POST["ddle_comment_link"]);
update_option('ddle_comment_num', (bool) $_POST["ddle_comment_num"]);
update_option('ddle_comments_none', (bool) $_POST["ddle_comments_none"]);
update_option('ddle_limit', (string) $_POST["ddle_limit"]);
update_option('mattc_categoryname', (string) $_POST["mattc_categoryname"]);
update_option('mattc_removeduplicates', (string) $_POST["mattc_removeduplicates"]);
echo 'Configuration Updated!
';
} ?>
prefix;
$ddle_header = get_option('ddle_header');
$ddle_sort = get_option('ddle_sort');
$ddle_hide_protected = get_option('ddle_hide_protected');
$ddle_show_date = get_option('ddle_show_date');
$ddle_date_format = get_option('ddle_date_format');
$ddle_excerpts = get_option('ddle_excerpts');
$ddle_chars = (int)get_option('ddle_chars');
$ddle_comment_link = (bool)get_option('ddle_comment_link');
$ddle_comment_num = (bool)get_option('ddle_comment_num');
$ddle_comments_none = (bool)get_option('ddle_comments_none');
$ddle_limit = (int)get_option('ddle_limit');
$hide_check = '';
if ($ddle_hide_protected) {
$hide_check = " AND post_password = '' ";
}
$sort_code = 'ORDER BY cat_name ASC, post_date DESC';
switch ($ddle_sort) {
case 'cata':
$sort_code = 'GROUP BY cat_name, post_date DESC';
break;
case 'catd':
$sort_code = 'ORDER BY cat_name DESC, post_date DESC';
break;
case 'datea':
$sort_code = 'ORDER BY post_date ASC';
break;
case 'dated':
$sort_code = 'ORDER BY post_date DESC';
break;
}
$the_output = NULL;
if ($ver < 2.3) {
$last_posts = (array)$wpdb->get_results("
SELECT post_date, ID, post_title, cat_name, cat_ID
FROM {$tp}posts, {$tp}post2cat, {$tp}categories
WHERE {$tp}posts.ID = {$tp}post2cat.post_id
AND {$tp}categories.cat_ID = {$tp}post2cat.category_id
AND post_status = 'publish'
AND post_type != 'page'
AND post_date < NOW()
{$hide_check}
{$sort_code}
");
} else { // post 2.3
if (get_option('mattc_removeduplicates')){
$last_posts = (array)$wpdb->get_results("SELECT ID, post_title, post_date, {$tp}terms.name as cat_name, {$tp}terms.term_id as cat_ID FROM (((({$tp}posts INNER JOIN {$tp}term_relationships ON {$tp}posts.ID = {$tp}term_relationships.object_id) INNER JOIN {$tp}term_taxonomy ON {$tp}term_relationships.term_taxonomy_id = {$tp}term_taxonomy.term_taxonomy_id) INNER JOIN {$tp}terms ON {$tp}term_taxonomy.term_id = {$tp}terms.term_id)) WHERE {$tp}term_taxonomy.taxonomy = 'category' AND {$tp}posts.post_status = 'publish' AND {$tp}posts.post_type = 'post' AND {$tp}posts.post_date <( NOW() + 86400 ) AND post_password = '' GROUP BY {$tp}posts.ID {$hide_check} {$sort_code};");
}else{
$last_posts = (array)$wpdb->get_results("SELECT post_date, distinct ID, post_title, {$tp}terms.name as cat_name, {$tp}terms.term_id as cat_ID FROM {$tp}posts, {$tp}terms, {$tp}term_taxonomy, {$tp}term_relationships WHERE {$tp}posts.ID = {$tp}term_relationships.object_id AND {$tp}term_relationships.object_id = {$tp}posts.ID AND {$tp}term_relationships.term_taxonomy_id = {$tp}term_taxonomy.term_taxonomy_id AND {$tp}terms.term_id = {$tp}term_taxonomy.term_id AND {$tp}term_taxonomy.taxonomy = 'category' AND post_status = 'publish' AND post_type = 'post' AND post_date < NOW() {$hide_check} {$sort_code}");
}}
if (empty($last_posts)) {return NULL;}
$the_output .= stripslashes($ddle_header);
if ($ddle_sort == 'datea') {
$last_posts = array_reverse($last_posts);
}
$used_cats = array();;
$i = 0;
foreach ($last_posts as $posts) {
if (in_array($posts->cat_name, $used_cats)) {
unset($last_posts[$i]);
} else {
$used_cats[] = $posts->cat_name;
}
$i++;
}
$last_posts = array_values($last_posts);
if ($ddle_sort == 'datea') {
$last_posts = array_reverse($last_posts);
}
$the_output .= '';
$limit_check = 0;
foreach ($last_posts as $posts) {
if (($ddle_limit == 0) || ($limit_check < $ddle_limit)) {
$the_output .= '- ';
if(get_option('mattc_categoryname')){$the_output .= '';
if (get_option('ddle_cat_links')) {$the_output .= '' . $posts->cat_name . '';} else {$the_output .= $posts->cat_name;}
$the_output .= ': ';}
$the_output .= '' . $posts->post_title . '';
if ($ddle_show_date) {
$the_output .= ' - ' . date_i18n($ddle_date_format, strtotime($posts->post_date));
}
if ($ddle_comment_link) {
$result = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1' AND comment_post_ID = '" . $posts->ID . "'";
$num_comments = $wpdb->get_var($result);
if ($ddle_comments_none || ($num_comments != 0)) {
$the_output .= '('.$num_comments.')';
}
}
if ($ddle_excerpts) {
$the_text = $wpdb->get_var("SELECT post_content FROM " . $tp . "posts WHERE ID=" . $posts->ID);
$the_output .= '
';
$the_output .= substr(strip_tags(trim($the_text)) , 0, $ddle_chars);
if (strlen(strip_tags(trim($the_text))) > $ddle_chars) {
$the_output .= "...";
}
}
$the_output .= ' ';
} // end limit if
$limit_check++;
}
$the_output .= '
';
return $the_output;}
function ddle_generate($content) {if (strpos($content, "") !== FALSE) {$content = str_replace("", dd_last_from_each(), $content);}return $content;}
add_filter('the_content', 'ddle_generate');
add_action('admin_menu', 'ddle_add_option_pages');
?>