Articles Options here. Version: 1.0 Author: Alex King Author URI: http://alexking.org */ load_plugin_textdomain('alexking.org'); function aka_install() { add_option('aka_columns', '1'); add_option('aka_token', '1'); } if (isset($_GET['activate']) && $_GET['activate'] == 'true') { if (get_option('aka_columns') == '') { aka_install(); } } function aka_request_handler() { if (isset($_POST['ak_action'])) { switch ($_POST['ak_action']) { case 'aka_update_settings': aka_update_settings(); break; } } } add_action('init', 'aka_request_handler'); function aka_head() { if (get_option('aka_columns') == 2) { print(' '); } } add_action('wp_head', 'aka_head'); function aka_update_settings() { if (isset($_POST['aka_columns'])) { update_option('aka_columns', intval($_POST['aka_columns'])); } if (isset($_POST['aka_token'])) { update_option('aka_token', intval($_POST['aka_token'])); } header('Location: '.get_bloginfo('wpurl').'/wp-admin/options-general.php?page=articles.php&updated=true'); die(); } function aka_get_articles() { global $wpdb, $post_cache, $category_cache, $post; $columns = get_option('aka_columns'); $post_ids = array(); $cats = array(); $display_cats = array(); $sorted_cats = array(); $count_posts = 0; $output = ''; $now = gmdate("Y-m-d H:i:s",time()); $posts = $wpdb->get_results(" SELECT $wpdb->posts.* FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id WHERE post_status = 'publish' AND post_date_gmt < '$now' AND meta_key = 'article' AND meta_value = '1' GROUP BY $wpdb->posts.ID ORDER BY post_date_gmt DESC "); if (!$posts || count($posts) == 0) { return ''; } foreach ($posts as $post) { $post_cache[$post->ID] = $post; $post_ids[] = $post->ID; } update_post_category_cache(implode(',', $post_ids)); if (function_exists('get_categories')) { $all_cats = get_categories(); if (isset($category_cache[1])) { $cat_cache = $category_cache[1]; } } else { $all_cats = $wpdb->get_results(" SELECT * FROM $wpdb->categories "); $cat_cache = $category_cache; } foreach ($all_cats as $cat) { $cats['cat_'.$cat->cat_ID] = $cat; } foreach ($posts as $post) { if (isset($cat_cache[$post->ID])) { foreach ($cat_cache[$post->ID] as $cat) { $display_cats[$cat->cat_ID][] = $post; $count_posts++; } } } foreach ($display_cats as $cat => $posts) { $sorted_cats[$cats['cat_'.$cat]->category_nicename] = $cat; } ksort($sorted_cats); if ($columns == '2') { $half = 0; $output .= '
'.__('To add post to your Articles list, simply add a custom field to the post:', 'alexking.org').'
'.__('If you have enabled the token method above, you can simply add ###articles### to any post or page and your articles list will be inserted at that place in the post/page.', 'alexking.org').'
'.__('You can always add a template tag to your theme (in a page template perhaps) to show your articles list.', 'alexking.org').'
<php aka_show_articles(); ?>