Shopify将banner-image修改为banner-video

在Shopify中,将首页的banner从图片修改为视频需要进行一些主题代码的修改。以下是步骤指南:

步骤 1:准备视频

 需要准备一个视频文件,确保其格式和尺寸适合你的需求。将视频文件上传到 Shopify 的文件库中,路径为“管理 > 设置 > 文件”。(主要是要文件链接之后要用)

步骤 2:备份主题

在进行任何代码更改之前,建议备份主题,以防出现问题。通过复制当前主题来创建一个备份。(切记)

步骤 3:编辑主题代码

1. 进入在线商店主题编辑器

- 在 Shopify 管理员页面中,点击“在线商店 > 主题 > 操作 > 编辑代码”。

2. 找到image-banner相关文件

- 在`sections`文件夹中,image-banner.liquid文件(image-banner组件块代码)

- 在`assets`文件夹中,section-image-banner.css文件(image-banner组件块样式)

3. 替换代码,敲重点

 - image-banner.liquid文件修改

        1)下滑找到{% schema %}{% endschema %}代码块添加以下代码,要在settings[]里添加

{
      "type": "checkbox",
      "id": "video_background",
      "default": false,
      "label": "Has Video Background"
    },

        2)找到id为Banner的div,在div中class样式上,右滑到最后的分号位置,添加代码

{% if section.settings.video_background %} video-background{% endif %}

        3)之后在id为Banner的div标签里添加以下代码,视频链接为你的实际文件链接

{%- if section.settings.video_background -%}
    <div class="banner__media media video-background">  
      <video autoplay muted loop id="myVideo">
        <source src="视频链接" type="video/mp4">
        Your browser does not support HTML5 video.
      </video>
    </div>                                                                                                                      
  {%- endif -%}

        4) 找到 {%- elsif section.settings.image_2 == blank -%},添加以下代码(注意是在标签内加)

and section.settings.video_background == false

    - section-image-banner.css文件修改:添加以下样式(响应式),具体高度需要根据你上传的视频文件进行调整

.media.video-background>*:not(.zoom):not(.deferred-media__poster-button) {
  height: auto;
}

@media screen and (max-width: 749px) {
  .banner--large.video-background:not(.banner--mobile-bottom):not(.banner--adapt) .banner__content {
      min-height: 27rem;
  }
}
  
@media screen and (min-width: 750px) {
  .banner--large.video-background:not(.banner--adapt) {
      min-height: 39rem;
  }
}
  
@media screen and (min-width: 990px) {
  .banner--large.video-background:not(.banner--adapt) {
      min-height: 52rem;
  }
}

  
@media screen and (min-width: 1320px) {
  .banner--large.video-background:not(.banner--adapt) {
      min-height: 62rem;
  }
}

步骤 4:保存和预览

1. 保存对代码的更改。

2. 回到Shopify商店预览页面,刷新以查看更改后的效果。

3. 没问题后将副本的代码块加入live theme,并保存

总结

通过这些步骤,你可以将Shopify首页的banner从图片修改为视频,缺点是,不能在模块里自定义上传视频,需要手动在后台修改视频链接

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要在基于@shopify/shopify-app-express的应用程序中注册Shopify Webhook,可以使用该框架提供的webhook路由。下面是一个示例代码来注册一个Webhook: ```javascript const { default: createShopifyAuth } = require('@shopify/koa-shopify-auth'); const { default: Shopify, ApiVersion } = require('@shopify/shopify-api'); const { verifyRequest } = require('@shopify/koa-shopify-auth'); const Koa = require('koa'); const Router = require('koa-router'); const bodyParser = require('koa-bodyparser'); const app = new Koa(); const router = new Router(); const webhook = { topic: 'products/create', address: 'https://your-app.com/webhooks/products/create', format: 'json', }; app.use(bodyParser()); const shopifyAuth = createShopifyAuth({ // Your Shopify app API key and secret apiKey: process.env.SHOPIFY_API_KEY, secret: process.env.SHOPIFY_API_SECRET, // Your app URL appUrl: process.env.APP_URL, // Scopes to request on the merchant's behalf scopes: ['read_products', 'write_products', 'read_script_tags', 'write_script_tags'], // After authentication, redirect to the shop's home page afterAuth(ctx) { const { shop } = ctx.state.shopify; ctx.redirect(`https://${shop}/admin/apps/${process.env.SHOPIFY_API_KEY}`); }, }); // Register webhook router.post('/webhooks/products/create', verifyRequest({ returnHeader: true }), (ctx) => { console.log('New product created:', ctx.request.body); ctx.status = 200; }); (async function() { // Create an instance of Shopify const shopify = new Shopify({ apiKey: process.env.SHOPIFY_API_KEY, apiSecretKey: process.env.SHOPIFY_API_SECRET, shopName: ctx.session.shop, accessToken: accessToken, apiVersion: ApiVersion.October20, autoLimit: { calls: 2, interval: 1000, bucketSize: 35 }, }); // Register webhook await shopify.webhook.create(webhook); // Use the shopifyAuth middleware app.use(shopifyAuth); app.use(router.allowedMethods()); app.use(router.routes()); app.listen(process.env.PORT, () => { console.log(`Server listening on port ${process.env.PORT}`); }); })(); ``` 在上面的代码中,我们首先创建一个Shopify实例,并使用它来注册Webhook。然后,我们使用@shopify/shopify-app-express框架创建一个HTTP服务器,并为Webhook的URL路径创建一个POST路由。在路由处理程序中,我们可以处理接收到的Webhook数据。最后,我们使用Shopify API将Webhook注册到商店中。 注意,我们在Webhook地址中使用了公共URL,这意味着您需要在您的应用程序中设置公共URL,并将其用作Webhook地址。此外,您需要在Shopify后台中配置相应的Webhook主题,以便将Webhook发送到正确的URL地址。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值