Latest Post From Each Category'); add_option('mlp_sort', 'cata'); add_option('mlp_cat_links', TRUE); add_option('mlp_hide_protected', TRUE); add_option('mlp_show_date', TRUE); add_option('mlp_date_format', 'F jS, Y'); add_option('mlp_excerpts', FALSE); add_option('mlp_chars', 200); add_option('mlp_comment_link', FALSE); add_option('mlp_comment_num', FALSE); add_option('mlp_comments_none', FALSE); add_option('mlp_limit', 0); function mlp_add_option_pages() { if (function_exists('add_options_page')) { add_options_page('Latest Posts', 'Latest Posts', 8, __FILE__, 'mlp_options_page'); } } function mlp_options_page() { global $mlp_version; if (isset($_POST['set_defaults'])) { echo '

'; update_option('mlp_header', '

Latest Post From Each Category

'); update_option('mlp_sort', 'cata'); update_option('mlp_cat_links', TRUE); update_option('mlp_hide_protected', TRUE); update_option('mlp_show_date', TRUE); update_option('mlp_date_format', 'F jS, Y'); update_option('mlp_excerpts', FALSE); update_option('mlp_chars', 200); update_option('mlp_comment_link', FALSE); update_option('mlp_comment_num', FALSE); update_option('mlp_comments_none', FALSE); update_option('mlp_limit', 0); echo 'Default Options Loaded!'; echo '

'; } else if (isset($_POST['info_update'])) { update_option('mlp_header', (string) $_POST["mlp_header"]); update_option('mlp_sort', (string) $_POST["mlp_sort"]); update_option('mlp_cat_links', (string) $_POST["mlp_cat_links"]); update_option('mlp_hide_protected', (bool)$_POST["mlp_hide_protected"]); update_option('mlp_show_date', (bool) $_POST["mlp_show_date"]); update_option('mlp_date_format', (string) $_POST["mlp_date_format"]); update_option('mlp_excerpts', (bool) $_POST["mlp_excerpts"]); update_option('mlp_chars', (string) $_POST["mlp_chars"]); update_option('mlp_comment_link', (bool) $_POST["mlp_comment_link"]); update_option('mlp_comment_num', (bool) $_POST["mlp_comment_num"]); update_option('mlp_comments_none', (bool) $_POST["mlp_comments_none"]); update_option('mlp_limit', (string) $_POST["mlp_limit"]); echo 'Configuration Updated!'; echo '

'; } ?>

Latest Posts From Each Category v

">
Options
Header text
Sort order />   By category (ascending)
/>   By category (descending)
/>   By date (ascending)
/>   By date (descending)
Show link to comments />
Include number of comments />
Include link for posts with no comments />
Turn category names into links />
Hide password-protected posts />
Show date after listed posts />
Date format
( Use the standard PHP date() format )
Show first X characters of posts />
Number of characters to show
Limit list to X categories (0 = unlimited)
prefix; $mlp_header = get_option('mlp_header'); $mlp_sort = get_option('mlp_sort'); $mlp_cat_links = get_option('mlp_cat_links'); $mlp_hide_protected = get_option('mlp_hide_protected'); $mlp_show_date = get_option('mlp_show_date'); $mlp_date_format = get_option('mlp_date_format'); $mlp_excerpts = get_option('mlp_excerpts'); $mlp_chars = (int)get_option('mlp_chars'); $mlp_comment_link = (bool)get_option('mlp_comment_link'); $mlp_comment_num = (bool)get_option('mlp_comment_num'); $mlp_comments_none = (bool)get_option('mlp_comments_none'); $mlp_limit = (int)get_option('mlp_limit'); $hide_check = ''; if ($mlp_hide_protected) { $hide_check = " AND post_password = '' "; } $sort_code = 'ORDER BY cat_name ASC, post_date DESC'; switch ($mlp_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) { throw "don't support pre-2.3 wordpress"; } else { // post 2.3 $last_posts = (array)$wpdb->get_results(" SELECT post_date, 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($mlp_header); if ($mlp_sort == 'datea') { $last_posts = array_reverse($last_posts); } $used_cats = array();; $i = 0; foreach ($last_posts as $posts) { if (false) { 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 ($mlp_sort == 'datea') { $last_posts = array_reverse($last_posts); } $the_output .= ''; return $the_output; } function mlp_generate($content) { if (strpos($content, "") !== FALSE) { $content = str_replace("", mlp_last_from_each(), $content); } return $content; } add_filter('the_content', 'mlp_generate'); add_action('admin_menu', 'mlp_add_option_pages'); ?>