微信号暂时无法添加好友,想提醒一下各位盆友。
发现只能是手动添加文字到微信号那里,属实有些麻烦。
搞了一段弹窗公告的代码,大家也可以直接食用。
食用方法直接添加到你的网站header里就行了。代码在文末
这种食用也不是很简单,每次都要操作源码比较麻烦,还是集成到主题设置中比较方便。
本站主题用的***(知道的一定知道),首先添加后台设置项
1、添加后台设置项
勾选显示后出现设置公告窗口
当然这里需要设计js的联动,不然点击是没反应的。
- jQuery('#ts_gonggao').click(function() {
- jQuery('#section-ts_gonggao1').fadeToggle(400);
- });
- if (jQuery('#ts_gonggao:checked').val() !== undefined) {
- jQuery('#section-ts_gonggao1').show();
- }
2、前端调用
将公告源码放入单独php文件中,如我放在tsxcc/gg.php
在网站header里调用此文件,完成!
- <?php get_template_part('tsxcc/gg/gg'); ?>
源码详解:
外层 if (zm_get_option('ts_gonggao')) 如果启用则输出以下内容
内层调用文本框内容
<?php if ( zm_get_option('ts_gonggao1') ) { ?>
<?php echo stripslashes( zm_get_option('ts_gonggao1') ); ?>
<?php } ?>
测试后非常不错。
撒花
html代码
- <!-- 公告 -->
- <div class="layer"></div>
- <div id="globalAd">
- <div id='hero-img' style="background-color: #1a95ff;background: linear-gradient(to left, #5dadf3 0, #4583ca 100%);">
- </div>
- <div id='profile-img'>
- <img src="https://www.kqwq.com/wp-content/themes/xiaochen/img/lpgo114.png" />
- </div>
- <div id='content'>
- <p style="font-size: 15px;font-weight: bold;">2022年5月2日公告</p>
- <p style=" padding: 5px; ">微信小程序上线,欢迎体验!</p>
- <p style="padding: 5px 0 20px 0;color: #f00;font-weight: 450;">微信暂时无法添加好友请12号后再试!</p>
- <a onclick="closeGlobalAd();" class="btn btn-default" rel='nofollow'>朕已阅</a>
- <a href="https://www.kqwq.com" onclick="redirectUrlToActive();" class="btn btn-default" rel='nofollow'>点击访问</a>
- </div>
- </div>
- <!-- 公告 -->
css
- a {
- text-decoration: none!important
- }
- #globalAd {
- max-width: 400px;
- flex-basis: 100%;
- margin: 0 auto;
- background: #fff;
- border-radius: 10px;
- box-shadow: 0 0 30px rgba(0, 0, 0, .3);
- -webkit-box-shadow: 0 0 30px rgba(0, 0, 0, .3);
- overflow: hidden;
- position: fixed;
- display: none;
- margin: 0 auto;
- z-index: 10001
- }
- .layer {
- width: 100%;
- height: 100%;
- position: fixed;
- top: 0;
- left: 0;
- filter: alpha(opacity=50);
- opacity: .5;
- background: #000;
- z-index: 1000;
- display: none
- }
- #globalAd #hero-img {
- width: 100%;
- height: 100px;
- background: #007bff
- }
- #globalAd #profile-img {
- width: 80px;
- height: 80px;
- margin: -60px auto 0;
- border: 6px solid #fff;
- border-radius: 50%;
- box-shadow: 0 0 5px rgba(90, 90, 90, .3)
- }
- #globalAd #profile-img img {
- width: 100%;
- background: #fff;
- border-radius: 50%
- }
- #globalAd #content {
- text-align: center;
- width: 320px;
- margin: 0 auto;
- padding: 5px 0 20px
- }
- #container #content h1 {
- font-size: 29px;
- font-weight: 500;
- margin: 50px 0 0
- }
- #globalAd #content p {
- font-size: 15px;
- font-weight: 400;
- line-height: 1.8;
- color: #666;
- }
- #globalAd #content a {
- color: #ccc;
- font-size: 14px;
- margin: 0 10px;
- transition: color .3s ease-in-out;
- -webkit-transition: color .3s ease-in-out
- }
- #globalAd #content a:hover {
- color: #007bff
- }
- #globalAd #content .btn {
- background: none repeat scroll 0 0 #1ba1e2;
- border: 0;
- border-radius: 2px;
- color: #fff!important;
- cursor: pointer;
- font-family: open sans, hiragino sans gb, microsoft yahei, wenquanyi micro hei, Arial, Verdana, Tahoma, sans-serif;
- font-size: 14px;
- padding: 6px 10%
- }
- #globalAd #content .btn:hover,
- .yanshibtn:hover {
- background: none repeat scroll 0 0 #9b59b6;
- border: 0;
- border-radius: 2px;
- color: #fff!important;
- cursor: pointer;
- font-family: open sans, hiragino sans gb, microsoft yahei, wenquanyi micro hei, Arial, Verdana, Tahoma, sans-serif;
- font-size: 14px;
- padding: 8px 10%
- }
js
- jQuery.cookie = function(name, value, options) {
- if(typeof value != 'undefined') {
- options = options || {};
- if(value === null) {
- value = '';
- options.expires = -1;
- }
- var expires = '';
- if(options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
- var date;
- if(typeof options.expires == 'number') {
- date = new Date();
- var totalTime = 24 * 3600;
- var hour = date.getHours();
- var minutes = date.getMinutes();
- var seconds = date.getSeconds();
- var pastTime = 3600 * hour + 60 * minutes + seconds;
- var leftTime = totalTime - pastTime;
- date.setTime(date.getTime() + (options.expires * leftTime * 1000));
- } else {
- date = options.expires;
- }
- expires = '; expires=' + date.toUTCString();
- }
- var path = options.path ? '; path=' + (options.path) : '';
- var domain = options.domain ? '; domain=' + (options.domain) : '';
- var secure = options.secure ? '; secure' : '';
- document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
- } else {
- var cookieValue = null;
- if(document.cookie && document.cookie != '') {
- var cookies = document.cookie.split(';');
- for(var i = 0; i < cookies.length; i++) {
- var cookie = jQuery.trim(cookies[i]);
- if(cookie.substring(0, name.length + 1) == (name + '=')) {
- cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
- break;
- }
- }
- }
- return cookieValue;
- }
- };
- $(function() {
- var COOKIE_NAME = "tsxcc";
- if($.cookie(COOKIE_NAME)) {
- $(".layer").hide();
- $("#globalAd").hide();
- } else {
- var tsxccH = $(window).height();
- var tsxccW = $(window).width();
- $(".layer").show();
- $("#globalAd").css({
- 'top': tsxccH / 2 - $("#globalAd").height() / 2,
- 'left': tsxccW / 2 - $("#globalAd").width() / 2
- });
- $("#globalAd").slideDown(300, function() {
- setTimeout("closeGloableAd()", '300000');
- });
- $.cookie(COOKIE_NAME, "tsxcc", {
- path: '/',
- expires: 1
- });
- }
- });
- function closeGlobalAd() {
- $('#globalAd').hide();
- $('.layer').hide();
- }
- function redirectUrlToActive() {
- $('#globalAd').hide();
- $('.layer').hide();
- }