欢迎光临Software MyZone,有问题可留言或到站点论坛发帖,争取第一时间帮忙解决 || 站点论坛:火龙论坛 || 淘宝小店:应小心的易淘屋 【欢迎大家提建设性意见】

如何给wordpress添加返回顶部按钮

首先编辑一段js脚本,保存为return_top.js,代码如下:

var isie6 = window.XMLHttpRequest ? false : true;

function newtoponload()

{ var c = document.getElementById("full");

function b()

{ var a = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;

if (a > 0) {

if (isie6) { c.style.display = "none"; clearTimeout(window.show); window.show = setTimeout(function ()

{ var d = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;

if (d > 0) { c.style.display = "block"; c.style.top = (400 + d) + "px" } }, 300) }

else { c.style.display = "block" } }

else { c.style.display = "none" } }

if (isie6) { c.style.position = "absolute" } window.onscroll = b; b() }

if (window.attachEvent) { window.attachEvent("onload", newtoponload) }

else { window.addEventListener("load", newtoponload, false) }

document.getElementById("full").onclick = function () { window.scrollTo(0, 0) };

把js脚本放在wp-content文件夹下。
其次,在主题的footer.php文件的标签之后、标签之前的位置插入如下代码,并保存设置:

<div id="full" style="width: 50px; height: 95px; position: fixed; left: 50%; top: 425px; margin-left: 493px; z-index: 100; text-align: center; cursor: pointer;">

<a><img src="
/wp-content/top.png
" alt="返回顶部" border="0" /></a>

</div>
<div id="full" style="width:50px; height:95px; position:fixed; left:50%; top:425px; margin-left:493px;  z-index:100; text-align:center; cursor:pointer;">

<a><img src="/wp-content/top.png" border=0 alt="返回顶部"></a>

</div>
<script src="/wp-content/return_top.js" type="text/javascript"></script>

摘自(有改动):http://www.datacentersky.com/taught-you-how-to-add-wordpress-back-to-top-button.html