Posts by category');
function pc_add_option_pages() {
if (function_exists('add_options_page')) {
add_options_page('List Posts by Categories', 'Posts by category', 8, __FILE__, 'pc_options_page');
}
}
function pc_options_page() {
if (isset($_POST['info_update'])) {
?>
prefix;
$pc_header = get_option('pc_header');
$sort_code = 'ORDER BY cat_name ASC, post_date DESC';
$the_output = NULL;
$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}
");
if (empty($last_posts)) {
return NULL;
}
$the_output .= stripslashes($ddle_header);
$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);
$the_output .= '';
foreach ($last_posts as $posts) {
$the_output .= '- ' . apply_filters('list_cats', $posts->cat_name, $posts) . '
';
$where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND post_category=5" , $r );
$arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND ID IN (Select post_id FROM $wpdb->post2cat WHERE category_id =$posts->cat_ID) ORDER BY post_date DESC");
foreach ( $arcresults as $arcresult ) {
$the_output .= '- ' . apply_filters('the_title', $arcresult->post_title) . '
';
}
$the_output .= '';
}
$the_output .= '
';
return $the_output;
}
function pc_generate($content) {
$content = str_replace("", posts_by_category(), $content);
return $content;
}
add_filter('the_content', 'pc_generate');
add_action('admin_menu', 'pc_add_option_pages');
?>