user2982427
user2982427

Reputation:

Simplepie pagination

I'm trying to set up pagination as described here: http://simplepie.org/wiki/tutorial/how_to_do_item_paging, but it does not work since in my case there is an if statement that displays the title of only certain items which have the category defined as Apples in this simple example. Anyone know a way to do pagination with this example?

foreach ($feed->get_items() as $item):

if($item->get_category()->get_label() == 'Apples'){

    echo $item->get_title();

}

endforeach;

Upvotes: 0

Views: 240

Answers (1)

Purus
Purus

Reputation: 5799

1) Assign the $items to an associate array instead of directly using "echo" when the labels match.

2) Get count of the array using count() function

3) Splice the array using array_splice() to get only required number of items and the offset

array_splice($array,$start,$itemPerPage)

4) With the total array count and $itemPerPage you can make the pagination

About splicing: http://www.php.net/manual/en/function.array-splice.php

Upvotes: 1

Related Questions