• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Pagination for search module ?
PostPosted: Mon Feb 25, 2013 3:42 pm 
Offline
Power Poster
Power Poster

Joined: Fri Mar 30, 2007 2:28 am
Posts: 944
Location: London
Anyone managed to do pagination for the search module ?


Top
 Profile  
 
 Post subject: Re: Pagination for search module ?
PostPosted: Thu Mar 14, 2013 10:37 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1371
It's possible, I guess.. Seems like you can call a UDT in the search template that reads a 'searchpage' variable from the URL, and truncates the output based on the page number and pre-set number of records returned.. Previous and Next buttons would link to the same search results, but with a different 'searchpage' .. This would probably only work with search in 'get' mode.


Top
 Profile  
 
 Post subject: Re: Pagination for search module ?
PostPosted: Fri Mar 15, 2013 12:01 am 
Offline
Power Poster
Power Poster

Joined: Fri Mar 30, 2007 2:28 am
Posts: 944
Location: London
Hi Wayne

Hope you are well and not heard from the one who shall not be named !!!

Anyway I am seriously disappointed with your none answer given the Intel / NASA Scientist you purport to be !!!


Top
 Profile  
 
 Post subject: Re: Pagination for search module ?
PostPosted: Sat Mar 16, 2013 4:43 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1371
Jeez.. If you put it that way, I have a procedure for you.

This is tested on an old version (1.9.4.1) of CMSMS that I have lying around. Not tested with pretty URLs.

Note that for this to work, your {search} must be in 'get' mode. In this version, {search search_method='get'} still puts it in post mode. You need to remove the parameter, as {search} defaults to 'get'. Don't know if this bug has been fixed since.

Create a UDT called 'search_pagination' containing:

Code:
# Get parameters from URL and UDT call

$search_page = $_GET['search_page'] ? $_GET['search_page'] : 1;
$results_per_page = $params['results_per_page'] ? $params['results_per_page'] : 10;
$results = $params['results'];
$results_assign = $params['results_assign'];
$pagelinks_assign = $params['pagelinks_assign'];

# Chop off the beginning of the array based on page number and count the results remaining.

$num_results = count(array_slice($results, ($search_page - 1) * $results_per_page));

# Slice and dice the results array based on number of results per page and page number

$results = array_slice($results, ($search_page - 1) * $results_per_page, $results_per_page);

$pagelinks = new stdClass;

# link to prev page;

if ($search_page > 1) {
  $get = $_GET;
  $get['search_page'] = $search_page - 1;
  $pagelinks->prev = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?' . http_build_query($get);
}

# link to next page;

if ($num_results > $results_per_page) {
  $get = $_GET;
  $get['search_page'] = $search_page + 1;
  $pagelinks->next = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?' . http_build_query($get);
}

# dump to smarty

$smarty->assign($results_assign, $results);
$smarty->assign($pagelinks_assign, $pagelinks);


In the beginning of your results template, put a call to:

Code:
{search_paginate results_per_page=10 results=$results results_assign=results pagelinks_assign=pagelinks}

In the call above we're saying we want 10 results per page, use the $results array, overwrite the $results array with our paginated results, and create a $pagelinks variable containing our prev and next URLs.

At the end of your results template, create the prev and next links:

Code:
{if isset($pagelinks->prev)}
<a href="{$pagelinks->prev}">Previous</a>
{/if}

{if isset($pagelinks->next)}
<a href="{$pagelinks->next}">Next</a>
{/if}


Here's a working example:

http://1941.teamwishbone.com/

Type something like 'modules' in the search.. 4 results per page.

Pretty basic.. No error checking.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting