惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
V
Visual Studio Blog
G
Google Developers Blog
Blog — PlanetScale
Blog — PlanetScale
Last Week in AI
Last Week in AI
C
Check Point Blog
D
Docker
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
博客园 - 叶小钗
博客园 - 聂微东
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
MyScale Blog
MyScale Blog
WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
腾讯CDC
S
SegmentFault 最新的问题
博客园 - 【当耐特】

WordPress Plugin

How to Create an Audio Player Playlist from an XML File Copy Audio URL in Wonder Audio Player YouTube Error 153 | WordPress Plugin Wonder Lightbox JavaScript Events | WordPress Plugin How to Create a WordPress Gallery from an XML File How to Remove URL Query Parameters in Wonder Lightbox How to Add an Image to the Lightbox Gallery Without Showing It in the Grid Gallery How to Make the PDF Page Fit the Entire Lightbox Width When Opening a PDF File Double Tap to Play or Pause the WordPress Audio Player on Touch Devices
How to Dynamically Create a WordPress Image and Video Gal...
2024-10-09 · via WordPress Plugin

Plugin:

Wonder Grid Gallery, Version 18.6 or above

Tutorial:

When using the Wonder Grid Gallery plugin to create a WordPress gallery, you would normally add images or videos to the gallery through the plugin's gallery editor. This tutorial will guide you on how to add a list of WordPress Media Library IDs to the gallery shortcode, allowing you to use the same gallery setup to create different galleries or to dynamically create galleries using PHP code.

An online demo is below:

Step 1 - Create a Gallery in Wonder Grid Gallery

In Grid Gallery, create a new gallery. You don't need to add any images or videos to the gallery, as we will populate it using media IDs in the shortcode. However, if you do add any images or videos, they will appear at the beginning of the gallery.

If the gallery has categories, define the categories as well.

Step 2 - Add media IDs to the Shortcode

To add media IDs to the gallery, you can add a list of media IDs to the attribute mediaids in the gallery shortcode. The media IDs must be separated by commas, for example:

[wonderplugin_gridgallery id=60 mediaids="4311,4312,4305,4306,4308,4303,4304,4307"]

Extra Feature - Support Categories

If your gallery has categories, define them in the gallery editor. Then, you can add the list of media IDs to a category using the attribute mediaids-categoryslug. For example:

[wonderplugin_gridgallery id=60 mediaids-cat="4311,4312" mediaids-dog="4305,4306,4308,4303,4304,4307"]

Extra Feature - Image Size

In your WordPress dashboard, navigate to the left menu Wonder Grid Gallery -> Settings. There, you will find an option titled "Select the default image size from Media Library for grid thumbnails." By default, when creating the gallery using WordPress media IDs, the plugin will use the image size defined in this option for the images in the grid.

If you want to override this option, you can add the attribute data-mediaimagesize to the gallery shortcode. For example:

[wonderplugin_gridgallery id=60 mediaids="4311,4312,4305,4306,4308,4303,4304,4307" data-mediaimagesize="large"]

The available sizes are thumbnail, medium, large, and full.

Extra Feature - Lightbox

The lightbox option is enabled by default. If you want to disable the lightbox effect, you can add the attribute data-lightbox="false" to the shortcode. For example:

[wonderplugin_gridgallery id=60 mediaids="4311,4312,4305,4306,4308,4303,4304,4307" data-lightbox="false"]

The list of lightbox data options is as follows:

Data Option Description
data-lightbox true/false: enable/disable the lightbox effect
The default value is true
data-lightboxsize true/false: customise the lightbox size
The default value is false
data-lightboxwidth The maximum width of the lightbox
The default value is 960
data-lightboxheight The maximum height of the lightbox
The default value is 540