# 能否仅在首页添加横幅？

**URL:** <https://meta.discourse.org/t/can-i-add-a-banner-only-on-my-homepage/137178>\
**Category:** Support\
**Created:** [2019年十二月27日 17:37 UTC](https://meta.discourse.org/t/can-i-add-a-banner-only-on-my-homepage/137178 "2019-12-27T17:37:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wonmew](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wonmew/32/164834_2.png) [@wonmew](https://meta.discourse.org/u/wonmew)\
**Post date:** [2019年十二月27日 17:37 UTC](https://meta.discourse.org/t/can-i-add-a-banner-only-on-my-homepage/137178/1 "2019-12-27T17:37:44Z")

</div>

我想在首页添加一个横幅，但不是通过“横幅主题”来实现，因为我需要添加背景图片、文本或按钮。

> [@Add custom content that only appears on your homepage](https://meta.discourse.org/t/how-to-add-custom-content-that-only-appears-on-your-homepage/131415):
>
> A very common situation you’ll find yourself in as a theme developer is the need to create content that only shows on the homepage of your community. You might add some HTML to the “After Header” section of your theme, which will then appear on every page. You can jump through some hoops in CSS to hide this everywhere except the homepage… but instead let’s use a Discourse theme to create a component with content that is only visible on your homepage. If you’re unfamiliar with Discourse themes …

我按照该主题的操作，将第一部分代码放入我的 `<head>` 中，然后将剩余部分添加到“页眉后”标签页，但没有产生任何效果。我是不是哪里做错了？我能否仅在首页添加一个或两个自定义横幅？

---

<div class="post-metadata">

**Author:** ![hawm](https://avatars.discourse-cdn.com/v4/letter/h/f07891/32.png) [@hawm](https://meta.discourse.org/u/hawm)\
**Post date:** [2019年十二月27日 18:10 UTC](https://meta.discourse.org/t/can-i-add-a-banner-only-on-my-homepage/137178/2 "2019-12-27T18:10:14Z")

</div>

是的，你可能做错了，但由于你没有提供任何额外信息，我们无法得知。

---

<div class="post-metadata">

**Author:** ![wonmew](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wonmew/32/164834_2.png) [@wonmew](https://meta.discourse.org/u/wonmew)\
**Post date:** [2019年十二月27日 18:22 UTC](https://meta.discourse.org/t/can-i-add-a-banner-only-on-my-homepage/137178/3 "2019-12-27T18:22:15Z")

</div>

这是我添加到“页眉之后”的代码

```
<script type="text/x-handlebars" data-template-name="/connectors/below-site-header/custom- 
homepage">
   {{#if displayCustomHomepage}} 
    <div class="custom-homepage-wrapper wrap">
  
   
       <h1>我是约翰·多伊</h1>
       <p>我是一名摄影师</p>
  
    </div>
  </div>
   
   
   </div>
   {{/if}}
  </script>

```

如果我只添加 `<h1>我是约翰·多伊</h1> <p>我是一名摄影师</p>`，  
它会显示在顶部，但不仅仅是在主页上，而是所有页面都会显示。

---

<div class="post-metadata">

**Author:** ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)\
**Post date:** [2019年十二月27日 19:20 UTC](https://meta.discourse.org/t/can-i-add-a-banner-only-on-my-homepage/137178/4 "2019-12-27T19:20:15Z")

</div>

发布前请先使用搜索功能。

顺便提一下，[Versatile Banner](https://meta.discourse.org/t/versatile-banner/109133) 也具备您所需的功能。

---

<div class="post-metadata">

**Author:** ![JimPas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jimpas/32/148179_2.png) [@JimPas](https://meta.discourse.org/u/JimPas)\
**Post date:** [2019年十二月27日 20:57 UTC](https://meta.discourse.org/t/can-i-add-a-banner-only-on-my-homepage/137178/5 "2019-12-27T20:57:01Z")

</div>

您也可以查看此链接（包含在上方 Daniela 的链接主题中）。

> [@Homepage specific design and content](https://meta.discourse.org/t/homepage-specific-design-and-content/124406):
>
> Hello, I have an issue : I want a specific banner on the homepage only. I saw that it was possible but I don’t find any subject resolving my problem. Maybe, the fact that I’m still in trial is a factor. Can you help me please ? slightly_smiling_face

---

<div class="post-metadata">

**Author:** ![cokestroke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cokestroke/32/242007_2.png) [@cokestroke](https://meta.discourse.org/u/cokestroke)\
**Post date:** [2021年八月8日 13:48 UTC](https://meta.discourse.org/t/can-i-add-a-banner-only-on-my-homepage/137178/6 "2021-08-08T13:48:03Z")

</div>

所有代码都应放在部分，而不是在头部之后。
