教程代码并非截图所示样式,教程代码理论上wordpress通用,可以在任意的主题使用实况图预览,当然也并非百分百可用,仅理论实现此功能,如您有一定的代码基础,亦可按照适合自己主题的样式编写这个区块样式及功能
效果预览


实现原理
WordPress 中引入 LivePhotosKit JS 库来支持实况图,并创建一个自定义古腾堡区块
首先,我们需要在 WordPress 中引入 LivePhotosKit JS 库
在你的主题的 functions.php 文件中添加以下代码:
function enqueue_livephotoskit_script() {wp_enqueue_script('livephotoskit-js', 'https://cdn.apple-livephotoskit.com/lpk/1/livephotoskit.js', array(), null, true);}add_action('wp_enqueue_scripts', 'enqueue_livephotoskit_script');function enqueue_livephotoskit_script() { wp_enqueue_script('livephotoskit-js', 'https://cdn.apple-livephotoskit.com/lpk/1/livephotoskit.js', array(), null, true); } add_action('wp_enqueue_scripts', 'enqueue_livephotoskit_script');function enqueue_livephotoskit_script() { wp_enqueue_script('livephotoskit-js', 'https://cdn.apple-livephotoskit.com/lpk/1/livephotoskit.js', array(), null, true); } add_action('wp_enqueue_scripts', 'enqueue_livephotoskit_script');
这段代码将在你的 WordPress 站点上加载 LivePhotosKit JS 库
接下来,我们将创建一个自定义 Gutenberg 区块,使用户能够方便地在区块编辑器中添加支持实况图的区域
主题跟目录创建一个 JavaScript 文件 block.js
,并添加以下代码
详情点我
暂无评论内容