Wordpress-为每个类别设置默认的“特色图像”

Wordpress-为每个类别设置默认的“特色图像”,wordpress,Wordpress,我想为我拥有的每个类别设置一个默认的“特色图像” 在我的functions.php文件中,我有以下代码:- /* ---------------FEATURED POST IMAGE------------------------*/ function default_category_featured_image() { global $post; $featured_image_exists = has_post_thumbnail($post->ID); if (!$featured

我想为我拥有的每个类别设置一个默认的“特色图像”

在我的functions.php文件中,我有以下代码:-

/* ---------------FEATURED POST IMAGE------------------------*/
function default_category_featured_image() {
global $post;
$featured_image_exists = has_post_thumbnail($post->ID);
if (!$featured_image_exists) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );

if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment);
}}
else if ( in_category('2') ) {
set_post_thumbnail($post->ID, '112');
}
else if ( in_category('3') ) {
set_post_thumbnail($post->ID, '115');
}
else if ( in_category('4') ) {
set_post_thumbnail($post->ID, '113');
}
else if ( in_category('8') ) {
set_post_thumbnail($post->ID, '114');
}
else {
set_post_thumbnail($post->ID, '0');
}
}
}
add_action('the_post', 'default_category_featured_image');
除Wordpress外,它适用于大多数类别。目前有6篇文章以“Wordpress”作为分类,它们都使用分类ID“3”,但由于未知原因,一些以“Wordpress”作为分类的文章有默认的特色图像集,其中一些没有任何默认图像集

你知道为什么会这样吗-

您可以在这里看到问题:-


从主页上你可以看到标题“如何增加WordPress内存限制”正在发挥作用,“Web技巧WordPress十大最佳插件”现在正在运行,但它们具有相同的类别ID-有什么想法吗?

你可以为每个类别创建一个新模板,并执行分配类别的WP\U查询

然后在循环中,你可以说如果有特色的图像,显示,否则显示我的图像

如果这有道理的话。如果没有,我会尝试张贴一个例子很快。我在用自动取款机取款