Default featured image

描述

将默认的特色图片添加到媒体设置页面。如果未设置特色图像,则将显示该特色图像。就那么简单。

有关例外情况以及要使用的功能,请参见常见问题解答

欢迎建议

  • 发现了错误?
  • 想要帮助将其翻译成您的语言吗?
  • 有待改进吗?

与我联系

屏幕截图

  • 媒体页面上的设置
  • 媒体管理器将从当前选择的图像开始

安装

  1. 将文件夹解压缩到 /wp-content/plugins/ 目录
  2. 通过WordPress的“插件”菜单激活插件
  3. 转到“设置” -> “媒体” 页,然后选择一个图像。

常见问题

我选择的特色图片没有显示,为什么不起作用?

此插件不能保证它能正常工作。这取决于主题。我仍然想知道它是否失败,所以与我联系

我可以使用哪些功能来显示特色图像?

该插件使用默认的WordPress函数 the_post_thumbnail get_the_post_thumbnail has_post_thumbnail 将始终返回true。 get_post_thumbnail_id 将返回在帖子上设置的ID或您设置的DFI。

我可以排除页面还是给它一个不同图像?

是的,您可以使用内置的 dfi_thumbnail_id 过滤器。它将为您提供可用来检查的帖子ID。

请勿使用第23页的特色图片

function dfi_skip_page ( $dfi_id, $post_id ) {
  if ( $post_id == 23 ) {
    return 0; // invalid id
  }
  return $dfi_id; // the original featured image id
}
add_filter( 'dfi_thumbnail_id', 'dfi_skip_page', 10 , 2 );

对某些类别使用​​其他图像

以下示例仅在帖子具有“动物”类别的情况下有效。只分配“猫”是行不通的
为此,请勿嵌套 if

function dfi_category ( $dfi_id, $post_id ) {
  // all which have 'animals' as a category
  if ( has_category( 'animals', $post_id ) ) {

    //sub category
    if ( has_category( 'cats', $post_id ) ) {
      return 7; // cats img
    } else if has_category( 'dogs', $post_id ) {
      return 8; // dogs img
    }

    return 6; // default animals picture
  }
  return $dfi_id; // the original featured image id
}
add_filter( 'dfi_thumbnail_id', 'dfi_category', 10, 2 );

post_type’wiki’ 的不同图片

function dfi_posttype_book ( $dfi_id, $post_id ) {
  $post = get_post($post_id);
  if ( 'wiki' === $post->post_type ) {
    return 31; // the image id
  }
  return $dfi_id; // the original featured image id
}
add_filter( 'dfi_thumbnail_id', 'dfi_posttype_book', 10, 2 );

我可以更改返回图像的HTML吗?

是的,您可以使用过滤器 dfi_thumbnail_html

function dfi_add_class($html, $post_id, $default_thumbnail_id, $size, $attr) {
    // add a class to the existing class list
    $attr['class'] .= ' my-class';

    return wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
}
add_filter( 'dfi_thumbnail_html', 'dfi_add_class', 10, 5 );

评价

2021年8月6日
This plugin does its job as promised. Very quick and friendly support. If you need a default featured image - just use this plugin 🙂
2021年3月23日
Your solution helped us a lot especially in the beginning, when customer didn't had pretty much any images on the site. Thank you for taking a time with our cron-related problem!
2020年11月3日
Blog posts without a featured image could ruin a nice blog grid design with "ghost images". This is a perfect way to add a fallback version. A few plugin settings/options (different featured images for different post types and/or taxonomies, for example) would be nice. Maybe in a future pro version? But it can still be done with a few lines of code. Extra plus for quick and nice support.
阅读所有49条评价

贡献者及开发者

“Default featured image” 是开源软件。 以下人员对此插件做出了贡献。

贡献者

“Default featured image”插件已被翻译至9种本地话语言。 感谢所有译者为本插件所做的贡献。

将“Default featured image”翻译成您的语言。

对开发感兴趣吗?

您可以浏览代码,查看SVN仓库,或通过RSS订阅开发日志

更新日志

1.7.1

  • Fixed weird SVN deployment bug.

1.7.0

  • moved main class to it’s own file.
  • Added second class that can hold exceptions with other plugins
  • The first exception is for WP User Frontend
  • The second exception is for WP All Import.

1.6.4

  • 未指定meta_key的 get_post_meta($ post_id)找不到DFI。现在,它甚至将使用更深的级别并将其设置在核心缓存中。

1.6.3

  • 修复了阻止安装的插件标头。

1.6.2

  • 插件现在遵循WP编码标准
  • 修复了一个小错误,该错误导致DFI覆盖附件的特色图像。 mp3默认情况下具有音乐音符,DFI不应覆盖该音符。

1.6.1

  • 小自述文件 readme.txt 更新。

1.6

  • 在上次修复中,并不能解决所有情况。

1.5

  • 修复了两个小(罕见)警告
  • 添加了翻译域

1.4

  • 添加了插件图像,将插件标头都作为缩略图。基于 WP.org 在其主题预览中使用的boat
  • 修复了ajax调用未返回DFI的错误论坛线程

1.3

  • 过滤器 dfi_thumbnail_id 现在还返回正在调用的帖子(或任何postype)的帖子ID。有关新示例,请参见常见问题解答

1.2

  • 现在在更早的阶段调用了过滤器 dfi_thumbnail_id

1.1

  • 修复了图像的继承类

1.0

  • 插件现在将删除它在插件删除时的设置
  • <;img>;标记中添加了默认类(如果它显示默认的特色图像)
  • 现在,默认的特色图片也将返回 get_post_thumbnail_id ,从而使失败的可能性大大减小。
  • 媒体页面中给出的图像现已验证

0.9

  • 启动