我得到了一半的密码。对在这里。。。这段代码显示了每个类别的最新帖子,但没有缩略图。现在我们需要显示帖子中的缩略图。你会开始做改变吗?祝你一切顺利。。。
<?php
$ddle_version = \'1.92\';
// Setup defaults if options do not exist
add_option(\'ddle_header\', \'<h2>Latest Post From Each Category</h2>\');
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(\'ddle_exclude\', \'\');
add_option(\'ddle_include\', \'\');
add_option(\'ddle_max_per_cat\', 1);
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 \'<div id="message" class="updated fade"><p><strong>\';
update_option(\'ddle_header\', \'<h2>Latest Post From Each Category</h2>\');
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(\'ddle_exclude\', \'\');
update_option(\'ddle_include\', \'\');
update_option(\'ddle_max_per_cat\', 1);
echo \'Default Options Loaded!\';
echo \'</strong></p></div>\';
} else if (isset($_POST[\'info_update\'])) {
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(\'ddle_exclude\', (string) $_POST["ddle_exclude"]);
update_option(\'ddle_include\', (string) $_POST["ddle_include"]);
update_option(\'ddle_max_per_cat\', (string) $_POST["ddle_max_per_cat"]);
echo \'Configuration Updated!\';
echo \'</strong></p></div>\';
} ?>
<div class=wrap>
<h2>Latest Posts From Each Category v<?php echo $ddle_version; ?></h2>
<p>For information and updates, please visit:<br />
<a href="http://www.dagondesign.com/articles/latest-post-from-each-category-plugin-for-wordpress/">http://www.dagondesign.com/articles/latest-post-from-each-category-plugin-for-wordpress/</a></p>
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
<input type="hidden" name="info_update" id="info_update" value="true" />
<h3>Options</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="8">
<tr valign="top"><td width="35%" align="right">
Header text
</td><td align="left">
<input name="ddle_header" type="text" size="50" value="<?php echo get_option(\'ddle_header\') ?>"/>
</td></tr>
<tr valign="top"><td width="35%" align="right">
Sort order
</td><td align="left">
<input name="ddle_sort" type="radio" value="cata" <?php if (get_option(\'ddle_sort\') == "cata") echo "checked=\'checked\'"; ?> /> By category (ascending)<br />
<input name="ddle_sort" type="radio" value="catd" <?php if (get_option(\'ddle_sort\') == "catd") echo "checked=\'checked\'"; ?> /> By category (descending)<br />
<input name="ddle_sort" type="radio" value="datea" <?php if (get_option(\'ddle_sort\') == "datea") echo "checked=\'checked\'"; ?> /> By date (ascending)<br />
<input name="ddle_sort" type="radio" value="dated" <?php if (get_option(\'ddle_sort\') == "dated") echo "checked=\'checked\'"; ?> /> By date (descending)<br />
</td></tr>
<tr valign="top"><td width="35%" align="right">
Show link to comments
</td><td align="left">
<input type="checkbox" name="ddle_comment_link" value="checkbox" <?php if (get_option(\'ddle_comment_link\')) echo "checked=\'checked\'"; ?>/>
</td></tr>
<tr valign="top"><td width="35%" align="right">
Include number of comments
</td><td align="left">
<input type="checkbox" name="ddle_comment_num" value="checkbox" <?php if (get_option(\'ddle_comment_num\')) echo "checked=\'checked\'"; ?>/>
</td></tr>
<tr valign="top"><td width="35%" align="right">
Include link for posts with no comments
</td><td align="left">
<input type="checkbox" name="ddle_comments_none" value="checkbox" <?php if (get_option(\'ddle_comments_none\')) echo "checked=\'checked\'"; ?>/>
</td></tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr valign="top"><td width="35%" align="right">
Turn category names into links
</td><td align="left">
<input type="checkbox" name="ddle_cat_links" value="checkbox" <?php if (get_option(\'ddle_cat_links\')) echo "checked=\'checked\'"; ?>/>
</td></tr>
<tr valign="top"><td width="35%" align="right">
Hide password-protected posts
</td><td align="left">
<input type="checkbox" name="ddle_hide_protected" value="checkbox" <?php if (get_option(\'ddle_hide_protected\')) echo "checked=\'checked\'"; ?>/>
</td></tr>
<tr valign="top"><td width="35%" align="right">
Show date after listed posts
</td><td align="left">
<input type="checkbox" name="ddle_show_date" value="checkbox" <?php if (get_option(\'ddle_show_date\')) echo "checked=\'checked\'"; ?>/>
</td></tr>
<tr valign="top"><td width="35%" align="right">
Date format
</td><td align="left">
<input name="ddle_date_format" type="text" size="30" value="<?php echo get_option(\'ddle_date_format\') ?>"/>
<br />( Use the standard <a href="http://us3.php.net/date">PHP date() format</a> )
</td></tr>
<tr valign="top"><td width="35%" align="right">
Show first X characters of posts
</td><td align="left">
<input type="checkbox" name="ddle_excerpts" value="checkbox" <?php if (get_option(\'ddle_excerpts\')) echo "checked=\'checked\'"; ?>/>
</td></tr>
<tr valign="top"><td width="35%" align="right">
Number of characters to show
</td><td align="left">
<input name="ddle_chars" type="text" size="10" value="<?php echo get_option(\'ddle_chars\') ?>"/>
</td></tr>
<tr valign="top"><td width="35%" align="right">
Limit list to X categories
</td><td align="left">
<input name="ddle_limit" type="text" size="10" value="<?php echo get_option(\'ddle_limit\') ?>"/>
(0 = unlimited)
</td></tr>
<tr valign="top"><td width="35%" align="right">
Excluded category IDs
</td><td align="left">
<input name="ddle_exclude" type="text" size="30" value="<?php echo get_option(\'ddle_exclude\') ?>"/>
<br />(comma-separated list of cat IDs to exclude from lists)
</td></tr>
<tr valign="top"><td width="35%" align="right">
</td><td align="left"><strong>* OR *</strong>
</td></tr>
<tr valign="top"><td width="35%" align="right">
Included category IDs
</td><td align="left">
<input name="ddle_include" type="text" size="30" value="<?php echo get_option(\'ddle_include\') ?>"/>
<br />(comma-separated list of cat IDs to use)
</td></tr>
<tr valign="top"><td width="35%" align="right">
Maximum posts per category
</td><td align="left">
<input name="ddle_max_per_cat" type="text" size="10" value="<?php echo get_option(\'ddle_max_per_cat\') ?>"/>
(0 = unlimited)
</td></tr>
</table>
<div class="submit">
<input type="submit" name="set_defaults" value="<?php _e(\'Load Default Options\'); ?> »" />
<input type="submit" name="info_update" value="<?php _e(\'Update options\'); ?> »" />
</div>
</form>
</div><?php
}
function dd_last_from_each() {
global $wpdb, $post, $wp_version;
$ver = (float)$wp_version;
$tp = $wpdb->prefix;
$ddle_header = get_option(\'ddle_header\');
$ddle_sort = get_option(\'ddle_sort\');
$ddle_cat_links = get_option(\'ddle_cat_links\');
$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\');
$ddle_exclude = get_option(\'ddle_exclude\');
$ddle_include = get_option(\'ddle_include\');
$ddle_max_per_cat = get_option(\'ddle_max_per_cat\');
$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;
$mysqlnow = current_time(\'mysql\');
if ($ver < 2.3) {
$cat_list_code = \'\';
if (trim($ddle_exclude) != \'\') {
$ddle_exclude = (array)explode(\',\', $ddle_exclude);
foreach ($ddle_exclude as $de) {
$cat_list_code .= " AND cat_ID != \'" . trim(mysql_escape_string($de)) . "\' ";
}
} else if (trim($ddle_include) != \'\') {
$ddle_include = (array)explode(\',\', $ddle_include);
$cat_list_code .= " AND ( ";
$cat_tmp = array();
foreach ($ddle_include as $de) {
$cat_tmp[] .= " cat_ID = \'" . trim(mysql_escape_string($de)) . "\' ";
}
$cat_list_code .= implode(" OR ", $cat_tmp);
$cat_list_code .= " ) ";
}
$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 < \'$mysqlnow\'
{$cat_list_code}
{$hide_check}
{$sort_code}
");
} else { // post 2.3
$cat_list_code = \'\';
if (trim($ddle_exclude) != \'\') {
$ddle_exclude = (array)explode(\',\', $ddle_exclude);
foreach ($ddle_exclude as $de) {
$cat_list_code .= " AND {$tp}terms.term_id != \'" . trim(mysql_escape_string($de)) . "\' ";
}
} else if (trim($ddle_include) != \'\') {
$ddle_include = (array)explode(\',\', $ddle_include);
$cat_list_code .= " AND ( ";
$cat_tmp = array();
foreach ($ddle_include as $de) {
$cat_tmp[] .= " {$tp}terms.term_id = \'" . trim(mysql_escape_string($de)) . "\' ";
}
$cat_list_code .= implode(" OR ", $cat_tmp);
$cat_list_code .= " ) ";
}
$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 < \'$mysqlnow\'
{$cat_list_code}
{$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);
}
if ((int)$ddle_max_per_cat > 0) {
$used_cats = array();
foreach ($last_posts as $posts) {
$used_cats[$posts->cat_ID] = $ddle_max_per_cat;
}
$i = 0;
foreach ($last_posts as $posts) {
if ($used_cats[$posts->cat_ID] > 0) {
$used_cats[$posts->cat_ID] -= 1;
} else {
unset($last_posts[$i]);
}
$i++;
}
$last_posts = array_values($last_posts);
}
if ($ddle_sort == \'datea\') {
$last_posts = array_reverse($last_posts);
}
$the_output .= \'<ul>\';
$limit_check = 0;
$last_cat = NULL;
$multi_cats = FALSE;
if ($ddle_max_per_cat > 1)
$multi_cats = TRUE;
$result = array();
foreach ($last_posts as $posts) {
if (($ddle_limit == 0) || ($limit_check < $ddle_limit)) {
if ($last_cat != $posts->cat_ID) {
if ($last_cat != NULL) {
$the_output .= ($multi_cats) ? \'</ul></li>\' : \'\';
}
$the_output .= \'<li>\';
$the_output .= \'<b>\';
if ($ddle_cat_links) {
$the_output .= \'<a href="\' . get_category_link($posts->cat_ID) . \'">\' . $posts->cat_name . \'</a>\';
} else {
$the_output .= $posts->cat_name;
}
$the_output .= \'</b>: \';
$the_output .= ($multi_cats) ? \'<ul><li>\' : \'\';
} else {
$the_output .= \'<li>\';
}
$the_output .= \'<a href="\' . get_permalink($posts->ID) . \'">\' . $posts->post_title . \'</a>\';
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 .= \' - <a href="\' . get_permalink($posts->ID) . \'#comments">\';
if ($ddle_comment_num) {
$the_output .= $num_comments . \' Comment\';
if ($num_comments != 1) {
$the_output .= \'s\';
}
} else {
$the_output .= \'Comments\';
}
$the_output .= \'</a>\';
}
}
if ($ddle_excerpts) {
$the_text = $wpdb->get_var("SELECT post_content FROM " . $tp . "posts WHERE ID=" . $posts->ID);
$the_output .= \'<br />\';
$the_output .= substr(strip_tags(trim($the_text)) , 0, $ddle_chars);
if (strlen(strip_tags(trim($the_text))) > $ddle_chars) {
$the_output .= "...";
}
}
$the_output .= \'</li>\';
$last_cat = $posts->cat_ID;
} // end limit if
$limit_check++;
}
$the_output .= \'</ul>\';
$the_output .= ($multi_cats) ? \'</li></ul>\' : \'\';
return $the_output;
}
function ddle_generate($content) {
if (strpos($content, "<!-- ddlastfromeach -->") !== FALSE) {
$content = str_replace("<!-- ddlastfromeach -->", dd_last_from_each(), $content);
}
return $content;
}
add_filter(\'the_content\', \'ddle_generate\');
add_action(\'admin_menu\', \'ddle_add_option_pages\');
?>