wearerequired / gallery-types
允许您定义特定主题的相册类型。
1.0.1
2018-01-13 11:04 UTC
Requires
- php: >=5.6
This package is auto-updated.
Last update: 2024-09-18 00:43:16 UTC
README
一个允许您定义特定主题相册类型的插件。感谢 Jetpack 的相册模块。
添加自定义相册类型
默认情况下,插件只支持一种类型,WordPress 默认缩略图网格。要添加更多类型,您可以使用 gallery_types.types
过滤器。
add_filter( 'gallery_types.types', function( $types ) { return array_merge( $types, [ 'slider' => [ 'label' => __( 'Slider', 'gallery-types' ), 'supports_columns' => false, ], ] ); } );
每种类型都有一个键(slider
),包含两个值:用于在选择菜单中显示的 label
和用于定义类型是否支持列的 supports_columns
。如果 supports_columns
设置为 false,则列选项将隐藏。
一旦用户选择了一种类型,短代码将获得一个新的 type
属性,其值为相册类型的键。
要更改默认选中类型,您可以使用 gallery_types.default-type
过滤器。
自定义相册输出
此插件不会更改相册短代码的输出。这需要成为您主题的一部分,可能如下所示
/** * Customizes the gallery shortcode output if the type attribute is set to 'slider'. * * @see gallery_shortcode() * * @param string $output The gallery output. Default empty. * @param array $attr Attributes of the gallery shortcode. * @return string HTML content to display gallery. */ function required_gallery_shortcode( $output, $attr ) { $is_slider = false; // Check if the type attribute is set. if ( isset( $attr['type'] ) && 'slider' === $attr['type'] ) { $is_slider = true; } // Return the default gallery if the type attribute isn't set. if ( ! $is_slider ) { remove_filter( 'post_gallery', 'required_gallery_shortcode', 10 ); $output = gallery_shortcode( $attr ); add_filter( 'post_gallery', 'required_gallery_shortcode', 10, 2 ); return $output; } // Override shortcode attributes. $attr['size'] = 'thumbnail'; $attr['link'] = 'file'; $attr['columns'] = 0; // Get default gallery output and wrap it in a custom container div. remove_filter( 'post_gallery', 'required_gallery_shortcode', 10 ); $output = gallery_shortcode( $attr ); add_filter( 'post_gallery', 'required_gallery_shortcode', 10, 2 ); return "<div class='gallery-slider'>$output</div>"; } add_filter( 'post_gallery', 'required_gallery_shortcode', 10, 2 );
贡献
构建任务
要更新压缩的 JavaScript 文件,您需要安装 Node.js。
# to install dependencies run:
npm install
# to update the file run:
npm run build