像maspress的下一个帖子小部件

时间:2011-10-23 16:41:51

标签: php javascript jquery wordpress wordpress-plugin

我想要包含一个像Mashable中看到的功能。这是下一个帖子小部件。如果您到达帖子的末尾,则会在右侧显示建议。我找到了这个http://clokey2k.com/blog/2011/09/08-mashables-cool-next-post-widget/的解决方案,但它对我不起作用。

我的表现如下:

1,将nextpost.js文件添加到网络服务器的根目录

$(function(){
//When should it be triggered in this case - when the '.next-link' is visible, but it could be the '.offset().bottom' of the article?
limit = $('.next-link').offset().top;
//Account for the height of the window - would have to readjust on resize;
target = limit - $(window).height();
//Hide the fancy fixed position box;
$nextbox = $('.next-box')
$nextbox.css({right: '-=150px'});
//Make a note of it's status;
visible = false

//Cue Magic - every time the window scrolls;
$(window).scroll(function(){
    //Where are we?
    current =  $(window).scrollTop();
    //Hit the target - show me the box;
    if(current >= target && visible == false){
        $nextbox.animate({right: '+=150px'}, 500);
        visible = true;
    }
    //Gone back up to re-read the article - hide it again!
    if(current < target && visible == true){
        $nextbox.animate({right: '-=150px'}, 500);
        visible = false;
    };
});

});

2,将以下代码放在头部:

<script type="text/javascript" src=".../nextpost.js"></script>

3,添加代码:

<div class="next-link">fb-share button</div>
<div class="next-box">code of a wp widget area</div>

问题是,小部件区域(下一个框)总是出现,不仅在我到达下一个链接部分时。我认为问题在于javascript集成。我该怎么办?

0 个答案:

没有答案