怎么給網(wǎng)站添加頂部通知欄? – wordpress開發(fā)

    一款貼心的wordpress主題如果準(zhǔn)備有通知欄,那就會讓用戶感到更加的舒適,來看看這個wordpress卡覅方法,給網(wǎng)站添加頂部通知欄

    一款貼心的wordpress主題如果準(zhǔn)備有通知欄,那就會讓用戶感到更加的舒適,來看看這個wordpress開發(fā)方法,給網(wǎng)站添加頂部通知欄。

    方法:

    制作了一段函數(shù),放在functions.php的<?php下面:

    //頂部通知欄
    if ( ! function_exists( 'lifet_function_notice' ) ) :
    	/**
    	 * 簡單的通知欄
    	 */
    	function lifet_function_notice() {
    		 if (!isset($_COOKIE['close_top_notice'])){ ?>
    			<div id="top_notice" class="black">
    				<div class="top_notice_close" onclick="pushdownclose();"></div>
    				<div class="top_notice_text_box">
    					<span class="top_notice_txt" onclick="pushdownyes();">
    						簡單的通知
    					</span>
    				<div class="header_button">
    					<!--關(guān)閉按鈕-->
    					<button class="top_notice_button" onclick="pushdownclose();">?X?</button>
    				 ? <!--了解按鈕-->	
    					<button class="top_notice_button">
    						<a href="#">
    						關(guān)閉
    						</a>
    					</button>
    					</div><!--.header_button-->
    				</div>
    			</div>
    				
    			<script>
    			//Set Cookies
    			function setCookie(c_name,value,expiredays){
    				var exdate=new Date()
    				exdate.setDate(exdate.getDate()+expiredays)
    				document.cookie=c_name+ "=" +escape(value)+
    				((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
    			}
    			 
    			function pushdownyes(){
    				setCookie("close_top_notice", true, 30);
    				window.location = "#";
    			}
    			function pushdownclose(){
    				setCookie("close_top_notice", true, 5);
    				document.getElementById('top_notice').style.display="none"; 
    			}
    			</script>
    			
    			<?php } 
    
    			echo "
    			<style type='text/css'>
    			/** 頂部通知欄 **/
                #top_notice{
                	font-weight: bold;
                	font-size: 12px;
                	padding: 16px;
                	color: #fff;
                	background-color: #444
                }
                .top_notice_text_box{
                    max-width: 980px;
                    margin: 0 auto;
                	padding: 0 6px;
                }
                
                .top_notice_close{
                	cursor: pointer;
                	float: right;
                	font-size: 18px;
                	margin-right: 13px;
                	padding: 5px 0 3px;
                }
                
                .header_button{
                	float:right;
                }
                .top_notice_button{/*通告欄按鈕樣式*/
                	margin-left: 10px;
                	padding: 4px 16px;;
                	float: right;
                	background-color: #f5f5f5;
                	cursor:pointer
                }
                .top_notice_button a{
                	text-decoration:none;
                }
                
                .top_notice_txt a{
                	color:#fff;
                }
                			
                </style>";
                	}endif;

    如何使用?

    在你需要的地方,例如在主題根目錄下header.php</body>下面添加以下代碼即可調(diào)用。

    <?php lifet_function_notice();//通知?>
    怎么給網(wǎng)站添加頂部通知欄? - wordpress開發(fā)

    開始介紹:

    網(wǎng)站有時需要一些通知來給所有訪客,所以我就參考了Google的“隱私條款變更通知”來制作了一個適用于任何網(wǎng)頁(包括 WordPress )的“ 通知欄 ”

    1、首先當(dāng)然先添加一下外觀樣式,將下列代碼添加至網(wǎng)頁的? <style> ?或CSS文件內(nèi)(也就是Wordpress主題目錄下的“樣式表 (style.css)”)(所有樣式均提取于Google)

    /** 頂部通知欄 **/
    #top_notice{
    	font-weight: bold;
    	font-size: 13px;
    	zoom: 1;
    	background-color: rgb(66, 114, 219);
    }
     
    .top_notice_text_box{
    	margin-left: 12px;
    }
     
    .top_notice_text{
    	padding: 8px 12px 6px 0;
    	zoom: 1;
    	color: #fff;
    }
     
    .top_notice_close{
    	cursor: pointer;
    	float: right;
    	font-size: 18px;
    	margin-right: 13px;
    	padding: 5px 0 3px;
    	float: right;
    	color: #bcc9e8;
    }
    .top_notice_button{
    	cursor: pointer;
    	display: inline-block;
    	margin-left: 10px;
    	padding: 8px 12px 6px;
    	zoom: 1;
    	color: rgb(188, 201, 232);
    	background-color: rgb(34, 85, 203);
    }
     
    .top_notice_button:hover{
    	color: #fff;
    }
    ?

    2、現(xiàn)在就需要添加HTML代碼了,我制作的代碼是先使用 PHP 判斷用戶是否存在已閱讀的Cookie,如果沒有就顯示通告,只需要把如下代碼加入網(wǎng)頁(也就是“header.php”文件)的? <body> ?后方就行啦!(注意把內(nèi)容修改為你自己需要通知的內(nèi)容)

    <?php if (!isset($_COOKIE['close_top_notice'])){ ?>
    <div id="top_notice">
    	<div class="top_notice_close" onclick="pushdownclose();"> × </div>
    	<div class="top_notice_text_box">
    		<span class="top_notice_text">通知內(nèi)容</span>
    		<div class="top_notice_button" onclick="pushdownyes();">“立刻閱讀”按鈕Value</div>
    		<div class="top_notice_button" onclick="pushdownclose();">關(guān)閉</div>
    	</div>
    </div>
     
    <script>
    //Set Cookies
    function setCookie(c_name,value,expiredays){
    	var exdate=new Date()
    	exdate.setDate(exdate.getDate()+expiredays)
    	document.cookie=c_name+ "=" +escape(value)+
    	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
    }
     
    function pushdownyes(){
    	setCookie("close_top_notice", true, 30);
    	window.location = "“立即閱讀”跳轉(zhuǎn)的鏈接";
    }
    function pushdownclose(){
    	setCookie("close_top_notice", true, 5);
    	document.getElementById('top_notice').style.display="none"; 
    }
    </script>
    <?php } ?>

    總結(jié)

    1、其實這個通知欄發(fā)揮空間可以很大,例如做成“最新文章”或“警告欄”等?怎么給網(wǎng)站添加頂部通知欄? - wordpress開發(fā)

    2、有問題可以回復(fù)哦?怎么給網(wǎng)站添加頂部通知欄? - wordpress開發(fā)

    在CSS?#top_notice{?加入?position: fixed;?應(yīng)該就可以固定在頂部啦~

    ? 版權(quán)聲明:本文章采用“姓名標(biāo)示-非商業(yè)性-相同方式分享 4.0 國際(CC BY-NC-SA 4.0)”于“暢想資源”發(fā)布,轉(zhuǎn)載時須以相同方式發(fā)布并注明“原文鏈接”!

    本文固定鏈接:https://www.arefly.com/zh-cn/wordpress-top-notice/

    題外:

    將部分代碼改成下方形式,可實現(xiàn):

    關(guān)閉瀏覽器后打開顯示

    function pushdownyes(){
    	setCookie("close_top_notice", true);
    	window.location = "“立即閱讀”跳轉(zhuǎn)的鏈接";
    }
    function pushdownclose(){
    	setCookie("close_top_notice", true);
    	document.getElementById('top_notice').style.display="none"; 
    }
    ?

    參考鏈接:

    PHP?setcookie()?函數(shù)

    setcookie()函數(shù)

    給TA贊賞
    共{{data.count}}人
    人已贊賞
    ??
    Npcink上的部份代碼及教程來源于互聯(lián)網(wǎng),僅供網(wǎng)友學(xué)習(xí)交流,若您喜歡本文可附上原文鏈接隨意轉(zhuǎn)載。
    無意侵害您的權(quán)益,請發(fā)送郵件至 1355471563#qq.com 或點擊右側(cè) 私信:Muze 反饋,我們將盡快處理。
    ?
    購物車
    優(yōu)惠劵
    搜索
    主站蜘蛛池模板: 亚洲视频在线一区| 一区二区三区观看免费中文视频在线播放| 美女福利视频一区| 亚洲爆乳无码一区二区三区| 精品乱人伦一区二区三区| 中文字幕在线观看一区二区 | 国产一区二区三区高清在线观看 | 亚洲熟女少妇一区二区| 国产一区二区三区免费观看在线| 国产精品亚洲午夜一区二区三区 | 激情内射日本一区二区三区| 制服丝袜一区在线| 中文字幕在线视频一区| 色欲AV蜜桃一区二区三| 清纯唯美经典一区二区| 一区二区三区午夜| 中文字幕日韩欧美一区二区三区| 中文字幕在线观看一区二区三区| 亚洲一本一道一区二区三区| 无码少妇精品一区二区免费动态| 国产成人av一区二区三区不卡| 色偷偷一区二区无码视频| 激情综合一区二区三区| 亚洲A∨精品一区二区三区| 国产一区二区视频免费| 成人精品一区二区三区电影| 一区二区传媒有限公司| 亚洲欧美国产国产一区二区三区| 无码人妻精品一区二区三区66| 亚洲线精品一区二区三区| 精品aⅴ一区二区三区| 久久精品国产一区二区三区 | 国产日韩精品一区二区三区在线 | 日韩视频一区二区在线观看 | 日本精品高清一区二区| 日韩精品无码一区二区三区AV | 久久精品无码一区二区三区日韩| 小泽玛丽无码视频一区| 国产一区二区三区乱码| 亚洲一区二区三区播放在线| 亚洲AV日韩综合一区尤物|