[WordPress] 外掛分享: Ajax Pagination and Infinite Scroll

首頁外掛目錄 › Ajax Pagination and Infinite Scroll
WordPress 外掛 Ajax Pagination and Infinite Scroll 的封面圖片
⚠ 此外掛已下架 — 不再更新維護,建議勿安裝。
3,000+
安裝啟用
★★★★
4.5/5 分(27 則評價)
3337 天前
最後更新
0%
問題解決
WordPress 3.6.0+ v2.0.1 上架:2015-09-08

內容簡介

這個外掛可在整個 WordPress 網站上使用 Ajax 載入分頁內容。該外掛可在文章、頁面、搜尋、自訂文章類型和 WooCommerce 上運作。在同一範本中分頁多組文章。

請參考演示網站。

我們正在尋找使用此外掛的網站,以展示在我們的展示頁面中。如果您有興趣,請將您網站的連結發送到[email protected]

這個外掛有三種分頁類型可供選擇。

無限滾動 - 當使用者滾動到螢幕底部時自動載入新文章。
載入更多按鈕 - 點擊以載入新文章。
分頁 - 正常的分頁,但是使用 Ajax 載入下一頁。

設定方式

若需更多協助,請參考這個影片。
一旦安裝此外掛,請前往設定 -> Ajax 分頁設定。
選擇一個適用的主題默認值。如果您的主題不在列表中,請新增正確的選擇器。
需要使用您的瀏覽器開發人員工具找到 4 個必要的選擇器。
'文章選擇器' - 包含所有文章/商品的選取器。
'文章選項' - 單個文章/商品的選取器。
'導覽選擇器' - 文章/商品導覽的選取器。
'下一步選擇器' - 導覽下一個鏈接的選取器。
選擇其中一個分頁類型。
添加可選的回調函數。
點擊 '保存更改'。

多個設定值

例如,如果您的網站同時運作 WooCommerce 和部落格,那麼這兩種模板可能會使用不同的選擇器,需要從管理設置進行不同的設置。

在螢幕頂部點擊 '新增'。
重複上面的設定步驟並點擊 '保存更改'。
在螢幕頂部,您可以在保存的設置之間進行導覽。

多組文章設定

可將多組文章查詢和顯示在同一範本中,並獨立分頁。需要在範本文件中進行特定的設置,此已在這裡中簡要介紹。

刪除設置

在螢幕頂部選擇要刪除的分頁設置。
向下滾動螢幕,然後點擊 '刪除'。

樣式設計 - 載入更多按鈕

載入更多按鈕被包裝在一個具有 CSS 類別名 .malinky-load-more 的 div 中,該按鈕具有 CSS 類別名 .malinky-load-more__button。
在您的主題 style.css 文件中設計這些。

初始化(設置)

當頁面首次加載時,該外掛會初始化,然後更新分頁使用 Ajax。如果您需要隨時重新初始化該外掛,請在您的 JavaScript 中調用以下函數。

MalinkyAjaxPaging.setUp();

如果您在電子商務網站上運行任何其他 JavaScript/Ajax,例如篩選,那麼這是有用的。

回調函式

在每次載入新的文章集之後在設定中添加您自己的 JavaScript 代碼。
回調函數接收兩個參數:loadedPosts(一個新文章的數組)和 url(加載的 URL)。

外掛標籤

開發者團隊

⬇ 下載最新版 (v2.0.1) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Ajax Pagination and Infinite Scroll」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

Load paged content with Ajax throughout your WordPress site. The plugin works on posts, pages, search, custom post types and WooCommerce. Paginate MULTIPLE sets of posts in the same template.
Take a look at the demo site.
We’re looking for websites that use the plugin to feature on a showcase page. If you’re interested please email a link to your website to [email protected].
There are 3 pagination types to choose from.

Infinite Scroll – Automatically load new posts when the user reaches the bottom of the screen.
Load More Button – Click to load new posts.
Pagination – Normal pagination but load the next page with Ajax.

Set Up

For additional help watch this video.
Once the plugin is installed navigate to Settings -> Ajax Pagination Settings.
Select an applicable theme default. If your theme isn’t listed then add the correct selectors.
There are 4 required selectors which can be found by using your browser developer tools.
‘Posts Selector’ The selector that wraps all of the posts/products.
‘Post Selector’ The selector of an individual post/product.
‘Navigation Selector’ The selector of the post/product navigation.
‘Next Selector’ The selector of the navigation next link.
Choose a pagination type.
Add an optional callback.
Click ‘Save Changes’.

Multiple Settings
If for example your site is running WooCommerce and also a Blog then the two templates will probably use different selectors and require a different set up from the admin settings.

Click ‘Add New’ at the top of the screen.
Repeat the set up steps above and click ‘Save Changes’.
At the top of the screen you can navigate between your saved settings.

Multiple Sets of Posts
It’s possible to query and display multiple sets of posts in the same template and independently paginate them. This requires a specific set up within the template file which has been outlined here.
Delete Setting

At the top of the screen select the pagination setting you wish to delete.
Scroll to the bottom of the screen and click ‘Delete’.

Styling Load More Button

The load more button is wrapped in a div with the css class .malinky-load-more and the button has the css class .malinky-load-more__button.
Style these in your themes style.css file.

Initialization (Setup)
The plugin is initialized when the page first loads and the pagination is then updated to use Ajax. If you need to reinitialize the plugin at anytime call the folowing function in your javascript.
MalinkyAjaxPaging.setUp();

This is useful if you run any other javascript / ajax on the page, for example filtering on an ecommerce site.
Callback

Add your own Javascript code in the settings which runs after each new set of posts are loaded.
Callback receives two parameters: loadedPosts (An array of the new posts) and url (The url that was loaded).

Custom Events
There are 3 custom events that are triggered. Bind to these events to perform your own actions.

malinkyPaginationInitialized. Triggered after initialization.
document.addEventListener('malinkyPaginationInitialized', function(e) {
console.log('PaginationInitialized');
});

malinkyLoadPostsStart. Triggered before new posts are loaded.
document.addEventListener('malinkyLoadPostsStart', function(e) {
console.log('LoadPostsStart');
});

malinkyLoadPostsComplete. Triggered after new posts are loaded.
document.addEventListener('malinkyLoadPostsComplete', function(e) {
console.log('LoadPostsComplete');
});

Events only function when using a single set of pagination on a page.

Isotope / Masonry
If your using an isotope / masonry layout then you’ll need to add a callback in the settings to layout the new posts when they are added. This should be in the following format.
$('.grid').isotope('reloadItems').isotope();

Change the reference to the class name .grid to your own container element.
Additional

If using infinite scroll there is an option to amend the buffer in pixels before the next set of posts are loaded.
If using load more button there is an option to amend the button text.
You can choose your own preloader.gif.
When using pagination the browser history is maintained allowing your visitors to use the browser back and forward buttons as expected.

Conditional Loading
By default the plugin loads on every page load. You can stop loading the Javascript and CSS by setting the following constants to false in your wp-config.php file.
define('MALINKY_LOAD_JS', false);
define('MALINKY_LOAD_CSS', false);

Or by adding these two lines to your functions.php
add_filter( 'malinky_load_js', '__return_false' );
add_filter( 'malinky_load_css', '__return_false' );

Once disabled you can load the Javascript and CSS in specific templates by adding the following before the wp_head().
global $malinky_ajax_pagination;
$malinky_ajax_pagination->malinky_ajax_pagination_styles();
$malinky_ajax_pagination->malinky_ajax_pagination_scripts();

延伸相關外掛

文章
Filter
Apply Filters
Mastodon