# 在B2主题圈子的帖子列表里随机插入广告，支持多种自定义选项

> 发布时间：2026-06-01 23:25
> 最后更新：2026-06-02 00:38
> 原文链接：https://tcbdb.com/578.html

无缝插入B2主题设置-圈子设置，前端广告效果跟发帖没啥区别，先看效果

![](https://s.tcbdb.com/wp-content/uploads/2026/06/20260601123231609.gif)

- 支持开启或关闭广告功能

- 支持多条广告随机展示

- 支持广告最小间隔多少帖子、最大间隔多少帖子

- 支持自定义广告主名称、头像、标签

- 支持自定义广告标题、描述、链接、图片、视频、自定义HTML

- 支持自定义文本以及链接

需要注意

同一个广告，如果同时设置了图片和视频，将优先显示视频，如果设置了自定义HTML，将优先显示自定义HTML内容！

![](https://s.tcbdb.com/wp-content/uploads/2026/06/20260601151538709.png)

![](https://s.tcbdb.com/wp-content/uploads/2026/06/20260601151538881.png)

![](https://s.tcbdb.com/wp-content/uploads/2026/06/20260601151538813.png)

**下面来讲如何实现在B2主题圈子的帖子列表里随机插入广告**

在子主题的`functions.php`文件中添加代码：

在`style.css`中添加代码：

`/*圈子随机AD*/
.circle-topic-ad-item{
    position: relative;
    border-top:1px solid #efefef;
    background-color: #fafafa
}
.topic-ad-box{
    position: relative
}
.topic-ad-avatar-icon{
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background-color: #f0f0f0;
    font-size: 18px;
    color: #8590a6
}
.topic-ad-box .topic-avatar img.b2-radius{
    width: 100%;
    height: 100%;
    object-fit: cover
}
.topic-ad-label{
    display: inline-block;
    background-color: #f0f0f0!important;
    color: #8590a6!important;
    border: none!important;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 2px;
    font-weight: normal;
    line-height: 1.4;
    margin-top: 2px
}
.topic-ad-sponsor-name{
    display: block;
    font-size: 15px;
    color: #494B4D;
    font-weight: 600;
    line-height: 1.3
}
.topic-ad-content{
    padding: 8px 20px 8px 68px
}
.topic-ad-link{
    display: block;
    color: inherit;
    text-decoration: none
}
.topic-ad-link:hover{
    color: inherit
}
.topic-ad-link h2{
    margin-bottom: 8px
}
.topic-ad-link p{
    color: #8590a6;
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 8px
}
.topic-ad-image{
    overflow: hidden;
    margin-top: 8px;
    max-width: 100%
}
.topic-ad-image img{
    width: 100%;
    height: auto;
    display: block;
    border-radius: 4px
}
.topic-ad-video{
    overflow: hidden;
    margin-top: 8px;
    max-width: 100%
}
.topic-ad-video video{
    width: 100%;
    height: auto;
    display: block;
    border-radius: 4px;
    background-color: #000
}
.topic-ad-footer{
    padding: 15px 20px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center
}
.topic-ad-date{
    font-size: 12px;
    color: #c0c0c0
}
.topic-ad-go-button{
    display: inline-block;
    padding: 4px 16px;
    border-radius: 3px;
    font-size: 13px;
    color: #fff;
    background-color: #8590a6;
    text-decoration: none;
    transition: background-color .2s
}
.topic-ad-go-button:hover{
    background-color: #727d8c;
    color: #fff
}
.topic-ad-custom-html{
    padding: 0px;
    position: relative
}
.topic-ad-custom-html img{
    max-width: 100%;
    height: auto
}

@media screen and (max-width:768px){
    .circle-topic-ad-item{
        padding:0
    }
    .topic-ad-content{
        padding: 6px 16px
    }
    .topic-ad-footer{
        padding: 15px 16px 16px
    }
    .topic-ad-avatar-icon{
        width: 36px;
        height: 36px
    }
    .topic-ad-sponsor-name{
        font-size: 14px
    }
    .topic-ad-label{
        font-size: 10px
    }
    .topic-ad-box .topic-avatar img.b2-radius{
        width: 100%;
        height: 100%;
        object-fit: cover
    }
    .topic-ad-custom-html{
        padding: 16px
    }
}
/*end*/`

然后将`circle-topic-list.php`文件上传到子主题的`TempParts/circle`文件夹中即可！

