內容簡介
此外掛主要針對主題開發人員,旨在簡化 WordPress 列表頁面(如存檔、作者、分類、搜尋、標籤列表等)的語義化、可用性分割控制器的建立。
受到「The Loop」和「WP_Query」的啟發,此外掛不會干擾主題開發人員操作,而是透過提供以下樣板標籤來建立所需的標記:
pp_has_pagination - 確定當前「檢視」是否有任何分頁顯示,即所瀏覽的內容是否跨越了多個頁面
pp_the_pagination - 開始分割上下文環境,應在每次循環迭代的開始呼叫
pp_rewind_pagination - 重置分割上下文環境,以便可以多次迭代分割循環
pp_is_current_page - 用於分割循環中,返回一個布林值,指示當前循環迭代是否為當前頁面
pp_has_previous_page - 用於分割循環中,返回一個布林值,指示是否有上一頁,例如在第 1 頁時就不存在上一頁
pp_has_next_page - 用於分割循環中,返回一個布林值,指示是否有下一頁,例如在第 N 頁時就不存在下一頁
pp_the_page_permalink - 用於分割循環中,將當前頁面的永久連結 URL 輸出
pp_the_previous_page_permalink - 用於分割循環中,將上一頁的永久連結 URL 輸出
pp_the_next_page_permalink - 用於分割循環中,將下一頁的永久連結 URL 輸出
pp_the_first_page_permalink - 用於分割循環中,將第一頁的永久連結 URL 輸出
pp_the_last_page_permalink - 用於分割循環中,將最後一頁的永久連結 URL 輸出
pp_the_page_num - 用於分割循環中,輸出正在迭代的當前頁面的頁碼
例如,以下樣板標籤的排列將提供一個基本的分頁控制:
<?php if (pp_has_pagination()) : ?>
<div class="pagination">
<!-- the previous page -->
<?php pp_the_pagination(); if (pp_has_previous_page()) : ?>
<a href="<?php pp_the_previous_page_permalink(); ?>" class="prev">newer stories</a>
<?php else : ?>
<span class="current prev">newer stories</span>
<?php endif; pp_rewind_pagination(); ?>
<!-- the page links -->
<?php while(pp_has_pagination()) : pp_the_pagination(); ?>
<?php if (pp_is_current_page()) : ?>
<span class="current"><?php pp_the_page_num(); ?></span>
<?php else : ?>
<a href="<?php pp_the_page_permalink(); ?>"><?php pp_the_page_num(); ?></a>
<?php endif; ?>
<?php endwhile; pp_rewind_pagination(); ?>
<!-- the next page -->
<?php pp_the_pagination(); if (pp_has_next_page()) : ?>
<a href="<?php pp_the_next_page_permalink(); ?>" class="next">older stories</a>
<?php else : ?>
外掛標籤
開發者團隊
原文外掛簡介
This plugin is primarily aimed at theme developers, and intends to ease the
creation of semantic, usable pagination controls for WordPress listings pages, such as
arhive, author, category, search, tag listings etc.
Inspired by The Loop and WP_Query, this plugin stays out of the theme
developer’s way, allowing her to create the markup needed by providing the
following template tags:
pp_has_pagination – determines whether the current ‘view’ has any pagination to display, i.e. whether the content being browsed spans more than 1 page
pp_the_pagination – initiates the pagination context, should be called at the beginning of each loop iteration
pp_rewind_pagination – resets the pagination context, so that the pagination loop can be iterated over multiple times
pp_is_current_page – for use in the pagination loop, returns a boolean indicating whether the current loop iteration is for the current page
pp_has_previous_page – for use in the pagination loop, returns a boolean indicating whether there is a previous page, e.g. when at page 1, there is no previous page
pp_has_next_page – for use in the pagination loop, returns a boolean indicating whether there is a next page, e.g. when at page N of N, there is no next page
pp_the_page_permalink – for use in the pagination loop, echos the permalink for the current page
pp_the_previous_page_permalink – for use in the pagination loop, echos the permalink for the previous page
pp_the_next_page_permalink – for use in the pagination loop, echos the permalink for the next page
pp_the_first_page_permalink – for use in the pagination loop, echos the permalink for the first page
pp_the_last_page_permalink – for use in the pagination loop, echos the permalink for the last page
pp_the_page_num – for use in the pagination loop, echos the page number of the current page being iterated over
For example, the following arrangement of template tags would provide a rudimentary pagination control:
The template tags on offer by this plugin provide the theme developer with an
unlimited array of possibilities for marking up the pagination control in a
semantic manner.
For more information, see the original blog post.
