In this case, paginate_links
is being called and is expected to return an array of links.
$args = array(
'prev_next' => false,
'type' => 'array'
);
paginate_links
– Retrieve paginated link for archive post pages. Technically, the function can be used to create paginated link list for any area ( e.g.: « Prev 1 … 3 4 5 6 7 … 9 Next » )
- prev_next (boolean) (optional) Whether to include the previous and next links in the list or not.
- type (string) (optional) Controls format of the returned value. Possible values are:
- ‘plain’ – A string with the links separated by a newline character.
- ‘array’ – An array of the paginated link list to offer full control of display.
- ‘list’ – Unordered HTML list.
The next bits are looping through each page. The as
lets you define any variable name you want to represent the value, the tutorial chose $page
.
foreach ( $pagination as $page )
If it contains the term current
then extra attributes are added to mark it for styling.
strpos( $page, 'current' )
Example output of the function might look like:
Array
(
[0] => <span class="page-numbers current">1</span>
[1] => <a class="page-numbers" href="http://example.com/page/2/">2</a>
[2] => <a class="page-numbers" href="http://example.com/page/3/">3</a>
[3] => <span class="page-numbers dots">…</span>
[4] => <a class="page-numbers" href="http://example.com/page/7/">7</a>
)
With prev_next
set to true
you would see something like:
Array
(
[0] => <a class="prev page-numbers" href="http://example.com/">« Previous</a>
[1] => <a class="page-numbers" href="http://example.com/">1</a>
[2] => <span class="page-numbers current">2</span>
[3] => <a class="page-numbers" href="http://example.com/page/3/">3</a>
[4] => <a class="page-numbers" href="http://example.com/page/4/">4</a>
[5] => <span class="page-numbers dots">…</span>
[6] => <a class="page-numbers" href="http://example.com/page/7/">7</a>
[7] => <a class="next page-numbers" href="http://example.com/page/3/">Next »</a>
)
If you want to experiment and check the output try:
$args = array (
'prev_next' => true,
'type' => 'array',
);
echo "<pre>";
ob_start();
print_r( paginate_links( $args ) );
esc_html_e( ob_get_clean() );