You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅在网站首页隐藏指定按钮元素?

实现仅在首页隐藏按钮的方案

要实现仅在网站首页隐藏这两个移动端自定义菜单按钮,你可以在现有模板逻辑中添加首页判断条件,当处于首页时不渲染按钮代码即可。

修改后的代码示例

<div class="mobile-bar sticky-bar">
    {% if j3.settings.get('mobileCustomMenuStatus1') and not is_homepage %}
    <a class="mobile-custom-menu mobile-custom-menu-1" href="{{ j3.settings.get('mobileCustomMenuLink1.href') }}" {{ j3.linkAttrs(j3.settings.get('mobileCustomMenuLink1.attrs')) }} style="margin-left:10px; margin-right:-30px">
        {{ j3.countBadge(j3.settings.get('mobileCustomMenuLink1.name'), j3.cache.update(j3.settings.get('mobileCustomMenuLink1.total')), j3.settings.get('mobileCustomMenuLink1.classes')) }}
    </a>
    {% endif %}
    
    {% if j3.settings.get('mobileCustomMenuStatus2') and not is_homepage %}
    <a class="mobile-custom-menu mobile-custom-menu-2" href="{{ j3.settings.get('mobileCustomMenuLink2.href') }}" {{ j3.linkAttrs(j3.settings.get('mobileCustomMenuLink2.attrs')) }}>
        {{ j3.countBadge(j3.settings.get('mobileCustomMenuLink2.name'), j3.cache.update(j3.settings.get('mobileCustomMenuLink2.total')), j3.settings.get('mobileCustomMenuLink2.classes')) }}
    </a>
    {% endif %}
</div>

关键说明

  • 首页判断变量:上述代码中使用 is_homepage 作为首页标识变量,你需要根据实际模板引擎的规则替换它。比如基于路径判断可改为 request.path != '/';若平台有内置首页检测变量(如部分CMS中的 home 或 is_frontpage),直接替换即可。
  • 逻辑叠加:在原有按钮启用状态判断(j3.settings.get('mobileCustomMenuStatusX'))的基础上,新增 and not 首页条件,确保仅在非首页且按钮启用时才渲染按钮。

内容的提问来源于stack exchange,提问作者Ozgur Yetgin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 04:15:40