We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

plugins and pagination

Development and Programming

transparentb's avatar
transparentb
24 posts
14 years ago
transparentb's avatar transparentb

I recently wrote my first EE plugin that will do some progressive filtering based on a form with multiple select boxes and then return a pipe delimited list of channel entries. I then call that plugin through an embedded template.

This is the code for the embedded template where filter_categories is my plugin:

{embed="videos/videos_listing" entry_ids="{exp:filter_categories:filter}"}

I thin call this embed (embed:entry_ids} in my channel:entries tag in another template. The code is as follows:

{exp:channel:entries channel="videos" limit="9" paginate="bottom" entry_id="{embed:entry_ids}" status="premium|free"}
            <input type="hidden" id="{embed:entry_ids}" />
            <a href="http://{title_permalink=" class="video">_                {if status == 'Free'}http://hotkeyit.com/images/free_video.png{/if}_                {entry_date format="%F %d"}_                <h4>{title}</h4>_                produced by <span>{coach}</span>_                {listing_label}_            </a>

                {paginate}
                <div id="pagination">
                    Page {current_page} of {total_pages}  —{pagination_links}
                </div>
                {/paginate}
            {/exp:channel:entries}

The problem is that when I hit the next page for pagination it tries to go through and redo the filtering all over again which then throws errors. Is there some specific code I need to put in my plugin to handle pagination within my plugin? I haven’t been able to find any documentation around this. Should I not do an embed and call the filter some other way?

Thanks for your help.

       
Aaron Waldon's avatar
Aaron Waldon
66 posts
14 years ago
Aaron Waldon's avatar Aaron Waldon

Hi transparentb!

I have seen your pleadings for help on Twitter for the last couple of days, so I thought I would jump in really quick.

You will need to get the offset for your entries (the index of the results you would want to display). You could do this pretty easily by specifying the offset (page, result, whatever you want to call it), as a segment in the URL. For example, if you wanted to start showing results from 20, you could simply append a 20 as the last segment of the URL, like so, in the pagination links you create in your plugin: http://www.example.com/vidoes/listing/20

And then making the offset a parameter for you plugin tag, like this:

{exp:filter_categories:filter offset="{segment_3}"}

Then, in your plugin you would add something like:

$offset = $this->EE->TMPL->fetch_param('offset', 0);
if ( ! is_numeric( $offset ) || $offset < 0 )
{
$offset = 0;
}
if ( $offset >= count( $results )
{
return $this->EE->TMPL->no_results();
}

And then, return the results from that offset. Something like the following should do the trick:

return array_slice( $results , $offset );

That would be 0 based pagination (EE generally uses 1 as the starting index, so you may need to tweak it a bit).

Hopefully that is enough info to get you moving in the right direction!

       
JohanD's avatar
JohanD
59 posts
14 years ago
JohanD's avatar JohanD

Hi,

dynamo should help too https://github.com/rsanchez/dynamo

Cheers, Johan

       
transparentb's avatar
transparentb
24 posts
14 years ago
transparentb's avatar transparentb

Thanks so much for your replies. I was at a complete halt.

Aaron - I will need some time to process what you have written within the context of my plugin. I think it may work. I also need to make sure my values are progressing throughout the pagination. My results are simply a pipe delimited list of entry_ids. I am thinking I could write this to cache and access it.

Johan - I will definitely take a look at Dynamo.

Thanks so much to both of you. I have some things to try.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.