Last 5 posts by %A');
add_option('ddpa_show_date', TRUE);
add_option('ddpa_date_format', 'F jS, Y');
add_option('ddpa_inc_current', FALSE);
add_option('ddpa_newest_first', TRUE);
add_option('ddpa_excluded_cats', '');
function ddpa_add_option_pages() {
if (function_exists('add_options_page')) {
add_options_page('Posts by Author', 'DDPostsByAuthor', 8, __FILE__, 'ddpa_options_page');
}
}
function ddpa_options_page() {
global $ddpa_version;
if (isset($_POST['set_defaults'])) {
echo '
';
update_option('ddpa_all_posts', TRUE);
update_option('ddpa_num', 5);
update_option('ddpa_header', 'Last 5 posts by %A
');
update_option('ddpa_show_date', TRUE);
update_option('ddpa_date_format', 'F jS, Y');
update_option('ddpa_inc_current', FALSE);
update_option('ddpa_newest_first', TRUE);
update_option('ddpa_excluded_cats', '');
echo 'Default Options Loaded!';
echo '
';
} else if (isset($_POST['info_update'])) {
echo '';
update_option('ddpa_all_posts', (bool) $_POST["ddpa_all_posts"]);
update_option('ddpa_num', (int) $_POST["ddpa_num"]);
update_option('ddpa_header', (string) $_POST["ddpa_header"]);
update_option('ddpa_show_date', (bool) $_POST["ddpa_show_date"]);
update_option('ddpa_date_format', (string) $_POST["ddpa_date_format"]);
update_option('ddpa_inc_current', (bool) $_POST["ddpa_inc_current"]);
update_option('ddpa_newest_first', (bool) $_POST["ddpa_newest_first"]);
update_option('ddpa_excluded_cats', (string) $_POST["ddpa_excluded_cats"]);
echo 'Configuration Updated!';
echo '
';
} ?>
prefix;
$ddpa_num = get_option('ddpa_num');
$ddpa_header = get_option('ddpa_header');
$ddpa_show_date = get_option('ddpa_show_date');
$ddpa_date_format = get_option('ddpa_date_format');
$ddpa_inc_current = get_option('ddpa_inc_current');
$ddpa_newest_first = get_option('ddpa_newest_first');
$ddpa_excluded_cats = get_option('ddpa_excluded_cats');
$c_post = $post->ID;
$c_author_id = $post->post_author;
// see if we show current post
if (!$ddpa_inc_current) {
$ddpa_inc_current = " AND ID != " . $c_post . " ";
} else {
$ddpa_inc_current = " ";
}
// sorting
$newest_check = ' ASC ';
if ($ddpa_newest_first) {
$newest_check = ' DESC ';
}
if ($ver < 2.3) {
// get excluded cat list
$exclude_check = ' ';
if (strlen(trim($ddpa_excluded_cats)) > 0) {
$t_exclude = (array)explode(',', $ddpa_excluded_cats);
foreach ($t_exclude as $t_e) {
$exclude_check .= ' AND category_id != ' . (int)$t_exclude[$i] . ' ';
}
}
$last_posts = (array)$wpdb->get_results("
SELECT ID, post_title, post_date, post_category
FROM {$tp}posts, {$tp}post2cat
WHERE post_author = {$c_author_id}
{$exclude_check}
AND {$tp}posts.ID = {$tp}post2cat.post_id
{$ddpa_inc_current}
AND post_status = 'publish'
AND post_date < NOW()
AND post_type = 'post'
GROUP BY ID
ORDER BY post_date {$newest_check}
LIMIT {$ddpa_num}
");
} else { // >= 2.3
// get excluded cat list
$exclude_check = ' ';
if (strlen(trim($ddpa_excluded_cats)) > 0) {
$t_exclude = (array)explode(',', $ddpa_excluded_cats);
foreach ($t_exclude as $t_e) {
$exclude_check .= ' AND ' . $tp . 'term_taxonomy.term_id != ' . (int)$t_e . ' ';
}
}
$last_posts = (array)$wpdb->get_results("
SELECT ID, post_title, post_date
FROM {$tp}posts, {$tp}term_relationships, {$tp}term_taxonomy
WHERE post_author = {$c_author_id}
AND {$tp}term_relationships.object_id = {$tp}posts.ID
AND {$tp}term_relationships.term_taxonomy_id = {$tp}term_taxonomy.term_taxonomy_id
{$exclude_check}
{$ddpa_inc_current}
AND post_status = 'publish'
AND post_date < NOW()
AND post_type = 'post'
GROUP BY ID
ORDER BY post_date {$newest_check}
LIMIT {$ddpa_num}
");
}
$author_info = $wpdb->get_row("
SELECT display_name
FROM {$tp}users
WHERE ID = {$c_author_id}
LIMIT 1
");
// fix up header
$ddpa_header = str_replace('%A', $author_info->display_name, $ddpa_header);
if (count($last_posts) > 0) {
$the_output = NULL;
$the_output .= $ddpa_header;
$the_output .= "";
foreach ($last_posts as $lpost) {
$the_output .= '- ' . $lpost->post_title . '';
if ($ddpa_show_date) {
$the_output .= ' - ' . date($ddpa_date_format, strtotime($lpost->post_date));
}
$the_output .= '
';
}
$the_output .= "
";
}
return $the_output;
}
function ddpa_generate($content) {
if (strpos($content, "") !== FALSE) {
$content = preg_replace('/\s*\s*<\/p>/i', "", $content);
$content = str_replace("", ddpa_show_posts(), $content);
}
if (is_single()) {
if (get_option('ddpa_all_posts')) {
return $content . ddpa_show_posts();
} else {
return $content;
}
} else {
return $content;
}
}
add_filter('the_content', 'ddpa_generate');
add_action('admin_menu', 'ddpa_add_option_pages');
?>