简体   繁体   English

Wordpress插件“无限滚动”(jQuery)破解帮助

[英]Wordpress plugin “infinite scroll” (jQuery) hack help

I am trying to make my wordpress blog (removed) work with the plugin "Infinite Scroll" in a way that you have to click "more posts" to load more, instead of by scrolling close to the bottom of the page (which is the plugin default). 我试图使我的wordpress博客(删除)使用插件“无限滚动”工作,你必须点击“更多帖子”加载更多,而不是通过滚动靠近页面的底部(这是插件默认)。

There are instructions and a demo on how to do it here: http://www.infinite-scroll.com/ 有关如何在此处执行此操作的说明和演示: http//www.infinite-scroll.com/

Scroll down to "Custom trigger, non-automatic. Twitter-style". 向下滚动到“自定义触发器,非自动。推特式”。

I just don't understand how to get it to work with my theme (twenty ten). 我只是不明白如何让它与我的主题(二十)一起工作。 I probably don't have the right selectors going on. 我可能没有正确的选择器继续。

Could anyone give me a quick synopsis of what I need to do to pull this off? 任何人都可以给我一个快速的概要,说明我需要做些什么来解决这个问题?

Since you are using Wordpress, you should install the Jetpack plugin and activate the Infinite-scroll option. 由于您使用的是Wordpress,因此您应该安装Jetpack插件并激活无限滚动选项。 There are configuration examples for the Twenty Ten, Eleven and Twelve themes. 有Twenty Ten,Eleven和Twelve主题的配置示例。 I think you will find it easier than trying to integrate infinite-scroll yourself. 我认为你会发现比尝试自己整合无限滚动更容易。

First, you have to find where the <div class="entry-content"> is. 首先,您必须找到<div class="entry-content">位置。 this is in your wp-content/themes/[themename] folder, in a file called index.php or loop.php. 这是在你的wp-content/themes/[themename]文件夹中,在一个名为index.php或loop.php的文件中。 after the closing </div> of the entry-content, add: 在entry-content的结束</div>之后,添加:

<div class="moreposts" style="display:none"
 onclick="$('div.moreposts').slideUp();$(document).trigger('retrieve.infscr');">
     Show more
</div>

<script>
$(document).ajaxError(function(e,xhr,opt){
    if (xhr.status == 404) $('div.moreposts').slideUp("normal", function() { $(this).remove(); } );
});
</script>

Now, in the infinite scroll config (Wordpress Admin -> Settings -> Infinite scroll), add this to the "Javascript to be called after the next posts are fetched" box: 现在,在无限滚动配置(Wordpress管理 - >设置 - >无限滚动)中,将此添加到“获取下一个帖子后要调用的Javascript”框中:

$(window).unbind('.infscr');
setTimeout("$('div.moreposts').slideDown();", 1000);

Finally style the button to make it look pretty (add to style.css): 最后设置按钮的样式以使其看起来很漂亮(添加到style.css):

.moreposts { 
    display:block; 
    border-radius:5px; -moz-border-radius:5px; -webkit-border-radius:5px; 
    border: 1px solid #ddd; 
    background: #efefef; 
    text-align: center; 
    font-weight: bold; 
    box-shadow: 2px 2px 2px rgba(50,50,50,0.4); color: #444; 
    text-decoration: none; 
    padding: 5px;
    margin-bottom: 20px;
    cursor: pointer;
}
.moreposts:hover { 
    background: #dfdfdf; 
    color: #222;
}

Note that this will do the first post load automatic, and the subsequent ones manual. 请注意,这将自动执行第一次后加载,以及后续的手动加载。 This is necessary for the script to hide the Before/Next buttons automatically. 这是脚本自动隐藏“上一个”/“下一个”按钮所必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM