给网站添加一个漂亮的公告弹窗

给网站添加一个漂亮的公告弹窗

用户未登录

给网站添加一个漂亮的公告弹窗

用户已登录

简单好看到爆炸,一天只弹一次,使用cookie记录;可以插入到自己网站,做一个弹窗广告或者说弹窗公告把网页的css资源引入到站点,再把BODY里面的内容粘贴到网站就做成了;效果源码是在网站扒的,做了一个简单的HTML文件,不想做个多修改的可以直接引用文件,只要简单修改一下文字内容即可。

下面内容是适配了鸟叔的begin主题的文件,并修改了后台框架添加了几项设置项;可以看一下

先贴样式:

    复制代码
  1. /*弹窗广告样式*/
  2. #globalAd {
  3. max-width: 600px;
  4. width: 100%;
  5. flex-basis: 100%;
  6. margin: 0 auto;
  7. background: #fff;
  8. border-radius: 10px;
  9. box-shadow: 0 0 30px rgba(0, 0, 0, .4);
  10. -webkit-box-shadow: 0 0 30px rgba(0, 0, 0, .4);
  11. overflow: hidden;
  12. position: fixed;
  13. display: none;
  14. z-index: 9999999999;
  15. }
  16.  
  17. .layer {
  18. width: 100%;
  19. height: 100%;
  20. position: fixed;
  21. top: 0;
  22. left: 0;
  23. filter: alpha(opacity=50);
  24. opacity: .6;
  25. background: #000;
  26. z-index: 9999999998;
  27. display: none;
  28. }
  29.  
  30. #globalAd #hero-img {
  31. width: 100%;
  32. height: 100px;
  33. background: #007bff;
  34. }
  35.  
  36. #globalAd #profile-img {
  37. width: 80px;
  38. height: 80px;
  39. margin: -60px 0 0 40px;
  40. border: 3px solid #fff;
  41. border-radius: 50%;
  42. box-shadow: 1px 1px 10px 0 rgba(0,90,90,.3);
  43. }
  44.  
  45. #globalAd #profile-img img {
  46. width: 100%;
  47. height: 100%;
  48. background: #fff;
  49. border-radius: 50%;
  50. }
  51.  
  52. #globalAd #pttcontent {
  53. width: 80%;
  54. margin: 0 auto;
  55. padding: 0 0 20px;
  56. text-align: center;
  57. }
  58.  
  59. #globalAd #pttcontent h1 {
  60. font-size: 18px;
  61. line-height: 30px;
  62. font-weight: 500;
  63. text-transform: uppercase;
  64. position: absolute;
  65. top: 60px;
  66. margin-left: 4em;
  67. color: #fff;
  68. }
  69.  
  70. #globalAd #pttcontent .title {
  71. padding: 10px;
  72. font-weight: 400;
  73. text-align: left;
  74. }
  75.  
  76. #globalAd #pttcontent .pttcontent {
  77. padding: 10px 10px 20px 40px;
  78. line-height: 22px;
  79. font-weight: 300;
  80. text-align: left;
  81. }
  82.  
  83. #globalAd #pttcontent a {
  84. color: #ccc;
  85. font-size: 14px;
  86. margin: 0 10px;
  87. transition: color .3s ease-in-out;
  88. -webkit-transition: color .3s ease-in-out;
  89. }
  90.  
  91. #globalAd #pttcontent a:hover {
  92. color: #007bff
  93. }
  94.  
  95. #globalAd #pttcontent .btn {
  96. background: none repeat scroll 0 0 #1ba1e2;
  97. border: 0;
  98. border-radius: 10px;
  99. color: #fff!important;
  100. cursor: pointer;
  101. font-family: open sans, hiragino sans gb, microsoft yahei, wenquanyi micro hei, Arial, Verdana, Tahoma, sans-serif;
  102. font-size: 14px;
  103. padding: 6px 10%;
  104. }
  105.  
  106. #globalAd #pttcontent .btn:hover,
  107. .yanshibtn:hover {
  108. background: none repeat scroll 0 0 #59b68b;
  109. border: 0;
  110. border-radius: 10px;
  111. color: #fff!important;
  112. cursor: pointer;
  113. font-family: open sans, hiragino sans gb, microsoft yahei, wenquanyi micro hei, Arial, Verdana, Tahoma, sans-serif;
  114. font-size: 14px;
  115. padding: 8px 10%;
  116. }

上面样式添加到主题的style.css文件最后;接下来打开footer.php文件添加下面代码:[erphpdown]

    复制代码
  1. <?php if ( zm_get_option('layer_open')){ ?><!--后台主题选项代码中是否启用弹窗-->
  2. <div class="layer"></div>
  3. <div id="globalAd">
  4. <div id="hero-img" style="background-color: #1a95ff;background: linear-gradient(to left, #5dadf3 0, #4583ca 100%);"></div>
  5. <?php global $user_identity,$user_level; wp_get_current_user(); if ($user_identity) { ?>
  6. <div id="profile-img">
  7. <?php if (zm_get_option('cache_avatar')) { ?>
  8. <?php global $userdata; wp_get_current_user(); echo begin_avatar($userdata->user_email, 64); ?>
  9. <?php } else { ?>
  10. <?php global $userdata; wp_get_current_user(); echo get_avatar($userdata->ID, 64); ?>
  11. <?php } ?>
  12. </div><!--代码是如果用户登录了就调用用户头像-->
  13. <div id="pttcontent">
  14. <h1><?php echo $user_identity; ?></h1><!--代码是如果用户登录了就调用用户名-->
  15. <?php } else { ?>
  16. <div id="profile-img">
  17. <img src="<?php echo zm_get_option('logo_small_b'); ?>" alt="logo"><!--代码是如果用户未登录了就调用站点名称前标志-->
  18. </div>
  19. <div id="pttcontent">
  20. <h1><?php bloginfo("name");?></h1><!--代码是如果用户未登录了就调用网站名-->
  21. <?php } ?>
  22. <div class="title"><?php echo zm_get_option('layer_title'); ?></div><!--代码是输出弹窗标题,如果后台未设置则不显示-->
  23. <div class="pttcontent"><?php echo zm_get_option('layer_content'); ?></div><!--代码是输出弹窗内容,如果后台未设置则不显示-->
  24. <a onclick="closeGlobalAd();" class="btn btn-default" rel="nofollow">朕已阅</a>
  25. <!--下面代码是输出访问地址可以在后台填写,如果后台未设置则显示网站首页-->
  26. <?php if (zm_get_option('layer_contentlink')) { ?>
  27. <a href="<?php echo zm_get_option('layer_contentlink'); ?>" onclick="redirectUrlToActive();" class="btn btn-default" rel="nofollow">点击访问</a>
  28. <?php } else { ?>
  29. <a href="<?php echo home_url(); ?>" onclick="redirectUrlToActive();" class="btn btn-default" rel="nofollow">点击访问</a>
  30. <?php } ?>
  31. </div>
  32. </div>
  33.  
  34. <script>
  35. jQuery.cookie = function(name, value, options) {
  36. if(typeof value != "undefined") {
  37. options = options || {};
  38. if(value === null) {
  39. value = '';
  40. options.expires = -1;
  41. }
  42. var expires = '';
  43. if(options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  44. var date;
  45. if(typeof options.expires == 'number') {
  46. date = new Date();
  47. var totalTime = 24 * 3600;
  48. var hour = date.getHours();
  49. var minutes = date.getMinutes();
  50. var seconds = date.getSeconds();
  51. var pastTime = 3600 * hour + 60 * minutes + seconds;
  52. var leftTime = totalTime - pastTime;
  53. date.setTime(date.getTime() + (options.expires * leftTime * 1000));
  54. } else {
  55. date = options.expires;
  56. }
  57. expires = '; expires=' + date.toUTCString();
  58. }
  59. var path = options.path ? '; path=' + (options.path) : '';
  60. var domain = options.domain ? '; domain=' + (options.domain) : '';
  61. var secure = options.secure ? '; secure' : '';
  62. document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  63. } else {
  64. var cookieValue = null;
  65. if(document.cookie && document.cookie != '') {
  66. var cookies = document.cookie.split(';');
  67. for(var i = 0; i < cookies.length; i++) {
  68. var cookie = jQuery.trim(cookies[i]);
  69. if(cookie.substring(0, name.length + 1) == (name + '=')) {
  70. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  71. break;
  72. }
  73. }
  74. }
  75. return cookieValue;
  76. }
  77. };
  78. $(function() {
  79. var COOKIE_NAME = "ptt";
  80. if($.cookie(COOKIE_NAME)) {
  81. $(".layer").hide();
  82. $("#globalAd").hide();
  83. } else {
  84. var pttH = $(window).height();
  85. var pttW = $(window).width();
  86. $(".layer").show();
  87. $("#globalAd").css({
  88. 'top': pttH / 2 - $("#globalAd").height() / 2,
  89. 'left': pttW / 2 - $("#globalAd").width() / 2
  90. });
  91. $("#globalAd").slideDown(300, function() {
  92. setTimeout("closeGloableAd()", '300000');
  93. });
  94. $.cookie(COOKIE_NAME, "ptt", {
  95. path: '/',
  96. expires: 1 //cookie保存时间
  97. });
  98. }
  99. });
  100.  
  101. function closeGlobalAd() {
  102. $('#globalAd').hide();
  103. $('.layer').hide();
  104.  
  105. }
  106.  
  107. function redirectUrlToActive() {
  108. $('#globalAd').hide();
  109. $('.layer').hide();
  110. }
  111. </script>
  112. <?php } ?>

[/erphpdown]代码添加到footer.php文件的<?php wp_footer(); ?>前面就好;最后向后台主题选项添加功能,代码为:

    复制代码
  1. $options[] = array(
  2. 'name' => '',
  3. 'desc' => '启用弹窗通知',
  4. 'id' => 'layer_open',
  5. 'std' => '0',
  6. 'type' => 'checkbox'
  7. );
  8.  
  9. $options[] = array(
  10. 'name' => '',
  11. 'desc' => '弹窗通知标题',
  12. 'id' => 'layer_title',
  13. "std" => "这是一个弹窗标题",
  14. 'type' => 'text'
  15. );
  16.  
  17. $options[] = array(
  18. 'name' => '',
  19. 'desc' => '弹窗通知内容',
  20. 'id' => 'layer_content',
  21. 'std' => '你知道吗?亲!<br>我们此后的征途是星辰大海 ^_^',
  22. 'type' => 'textarea'
  23. );
  24.  
  25. $options[] = array(
  26. 'name' => '',
  27. 'desc' => '弹窗通知内容链接地址',
  28. 'id' => 'layer_contentlink',
  29. 'std' => 'https://www.teelm.com/',
  30. 'type' => 'text'
  31. );
  32.  
  33. $options[] = array(
  34. 'id' => 'clear'
  35. );

添加在哪里看各位自己的想法,我是单独开了一个选项放里面的;做到这里基本就好了,如果有一些样式错乱请自行调整哈;记得在后台主题选项里要保存一下哈。

[wm_tips]该文收费内容适配的是知更鸟的Begin主题,其他主题需要做相应的修改,购买请谨慎,如购买可联系,本站提供有偿修改[/wm_tips]

© 版权声明
WP主题

Begin子主题

2020-5-5 14:57:54

WordpressWP插件

最新erphpdown个人中心美化

2020-5-28 17:50:25

3 条回复 A文章作者 M管理员
欢迎您,新朋友,感谢参与互动!

#点我打卡

  1. ningbai

    提示错误Fatal error: Call to undefined function zm_get_option() in /www/wwwroot/****/wp-content/themes/Loostrive/index.php on line 50,这个怎么解决

    • 权戈

      该内容适用于鸟叔的begin主题,其他主题需要做相应的修改

    • 权戈

      修改该函数(zm_get_option())为你主题的函数或者不用函数调用

个人中心
购物车
优惠劵
今日签到
私信列表
搜索
文章目录

『权戈网络』欢迎您!😊