ankitpokhrel / dynamic-featured-image
动态添加多张特色图片(文章缩略图)功能到文章、页面和自定义文章类型。
v3.7.0
2019-04-14 09:30 UTC
Requires (Dev)
- phpunit/phpunit: ~5.7
README
动态特色图片(WordPress插件)
该项目不再活跃维护。
动态添加多张特色图片(文章缩略图)功能到文章、页面和自定义文章类型。
概述
为什么只限制自己使用一张特色图片,如果可以用多张特色图片做一些很酷的事情呢?动态特色图片插件允许在文章或页面中拥有多张特色图片。它允许您为每个文章和页面添加不同数量的特色图片,这些图片可以被各种主题函数收集。当您使用其他插件、文章缩略图或使用特色图片的滑块时,这特别有用。
安装
- 解压缩并将
dynamic-featured-images
目录上传到插件目录(/wp-content/plugins/
),或从插件->添加新插件->上传
安装。 - 通过WordPress中的
插件
菜单激活插件。 - 如果您没有看到新的特色图片框,请点击位于WordPress管理界面右上角的
屏幕选项
,并确保已选择特色图片2
框。
Bower
bower install dynamic-featured-image
它如何工作?
- 插件激活成功后,转到文章或页面的
添加
或编辑
页面,您将注意到一个第二张特色图片的框。
- 点击
设置特色图片
图标,从“动态特色图片媒体选择器”弹出窗口中选择所需的图片,然后点击设置特色图片
。
- 点击
添加新
以添加新的特色图片或使用删除
链接删除特色图片框。
- 添加特色图片后,点击
发布
或更新
以保存特色图片。
注意:只有当您发布或更新文章时,特色图片才会保存。
文档
其他资源
可用函数列表
- get_image_id( $image_url )
- get_image_thumb( $image_url, $size = "thumbnail" )
- get_image_url( $attachment_id, $size = "full" )
- get_post_attachment_ids( $post_id )
- is_attached( $attachment_id, $post_id )
- get_image_title( $image_url )
- get_image_title_by_id( $attachment_id )
- get_image_alt( $image_url )
- get_image_alt_by_id( $attachment_id )
- get_image_caption( $image_url )
- get_image_caption_by_id( $attachment_id )
- get_image_description( $image_url )
- get_image_description_by_id( $attachment_id )
- get_nth_featured_image( $position, $post_id )
- get_all_featured_images( $post_id )
- get_featured_images( $post_id )
- get_link_to_image( $attachment_id )
仅允许在特定文章类型中使用DFI
您可以使用dfi_post_types
过滤器来允许DFI仅在某些文章类型中使用。
function allowed_post_types() {
return array('post'); //show DFI only in post
}
add_filter('dfi_post_types', 'allowed_post_types');
阻止DFI
使用dfi_post_type_user_filter
过滤器来阻止DFI从文章类型中。
function blocked_post_types() {
return array('page'); //block DFI in page
}
add_filter('dfi_post_type_user_filter', 'blocked_post_types');
更改元框默认文本
使用dfi_set_metabox_title
过滤器来更改元框默认标题(特色图片)
function set_metabox_title( $title ) {
return "My custom metabox title";
}
add_filter('dfi_set_metabox_title', 'set_metabox_title');
翻译指南
所有翻译都存储在languages
文件夹中。
如果您有兴趣将插件翻译成您的语言,请首先确保翻译尚未可用。文件名很重要,因为您应遵循特定格式以保持一致性。例如,如果您要将尼泊尔语翻译成尼泊尔,文件应命名为dynamic-featured-image-ne_NP.po
– dynamic-featured-image
为插件本身,ne
为语言,NP
为国家。
开发
- 如果您还没有安装,请安装PHPUnit和composer。
- 安装所需依赖
$ composer install
- 使用安装脚本构建测试
$ ./bin/install-wp-tests.sh <test-db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]
- 使用phpunit运行测试
$ ./vendor/bin/phpunit
- 将更改与WordPress 编码标准进行验证
$ phpcs <dfi-plugin-dir or filename>
关于此项目有任何问题?
请随时报告发现的任何错误。合并请求、问题和插件推荐都非常受欢迎!