定制 wearerequired/gallery-types 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wearerequired/gallery-types

Composer 安装命令:

composer require wearerequired/gallery-types

包简介

Allows you to define a theme specific gallery type.

README 文档

README

A plugin that allows you to define a theme specific gallery type. Props to Jetpack for their Gallery module.

Add custom gallery types

By default the plugin supports only one type, WordPress default thumbnail grid. To add more types you can use the gallery_types.types filter.

add_filter( 'gallery_types.types', function( $types ) {
	return array_merge( $types, [
		'slider' => [
			'label' => __( 'Slider', 'gallery-types' ),
			'supports_columns' => false,
		],
	] );
} );

Each type has a key (slider) with two values: label for the label displayed in the select menu and supports_columns to define whether the type supports columns. If supports_columns is set to false the columns option will be hidden.
Once a user selects a type the shortcode will get a new type attribute with the key of a gallery type as value.

To change the default selected type you can use the gallery_types.default-type filter.

Customize gallery output

This plugin does not change the ouput of the gallery shortcode. That needs to be part of your theme and could be something like this:

/**
 * 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 );

Contributing

Build Task

To update the minfied JavaScript file you need Node.js installed.

# to install dependencies run:
npm install

# to update the file run:
npm run build

统计信息

  • 总下载量: 2.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2018-01-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固