Sign in to follow this  
hellomoto

Search pagination

Recommended Posts

hellomoto    36

I have this 

$selector = 'template=boat_vessel, sort=-boat_date_list, limit=3, ';

$selected = [
  "make" => "",
  "hulls" => "",
  "mobility" => "",
  //"make/model" => "",
  "year" => "",
  "price" => "",
  "length" => "",
  "location" => "",
  //"keywords" => "",
];

if($input->get->make) {
  $selected["make"] = $sanitizer->text($input->get->make);
  $selector .= "boat_model|boat_manufacturer*=" . $selected["make"];
}
if($input->get->hulls) {
  $p = $pages->get('name=hulls, parent.name=options')->child('name=' . $sanitizer->pageName($input->get->hulls));
  if($p->id) {
    $selector .= "boat_model.mamo_hulls=$p, ";
    $selected["hulls"] = $p->title;
    $input->whitelist("hulls", $p->name);
  }
}
if($input->get->mobility) {
  $p = $pages->get('name=mobility, parent.name=options')->child('name=' . $sanitizer->pageName($input->get->mobility));
  if($p->id) {
    $selector .= "boat_model.mamo_mobility=$p, ";
    $selected["mobility"] = $p->title;
    $input->whitelist("mobility", $p->name);
  }
}
if($input->get->price_min || $input->get->price_max) {
  $selector .= "boat_price_list>={$input->get->price_min}, boat_price_list<={$input->get->price_max}, ";
  $selected["price"] = "{$input->get->currency} {$input->get->price_min} - {$input->get->price_max}";
}
if($input->get->length_min || $input->get->length_max) {
  $selector .= "boat_model.mamo_length_ft>={$input->get->length_min}, boat_model.mamo_length_ft<={$input->get->length_max}, ";
  $selected["length"] = "{$input->get->length_min} - {$input->get->length_max} ft.";
}

$form = '';

$form .= '<p>
  <label for="search_make">Manufacturer/Model</label>
  <input name="make" id="search_make" type="text" value="'.$selected["make"].'"/>
  </p>'; // manufacturer/model // make

$form .= '<p>
    <label for="search_hulls">Hull Configuration</label>
    <select name="hulls" id="search_hulls">
      <option value=""></option>';
foreach($pages->get('name=hulls, parent.name=options')->children() as $i) {
  if($selected['hulls'] == $i->title) $select = ' selected';
  else $select = '';
  $form .= '<option value="'.$i->name.'"'.$select.'>'.$i->title.'</option>';
}
$form .= '</select>
  </p>';

$form .= '<p>
    <label for="search_mobility">Mobility</label>
    <select name="mobility" id="search_mobility">
      <option value=""></option>';
foreach($pages->get('name=mobility, parent.name=options')->children() as $i) {
  if($selected['mobility'] == $i->title) $select = ' selected';
  else $select = '';
  $form .= '<option value="'.$i->name.'"'.$select.'>'.$i->title.'</option>';
}
$form .= '</select>
  </p>';

$form .= '<p>
  <label>Price</label>
  <input type="number" name="price_min" id="search_price_min" style="width:80px" placeholder="Minimum" value="'.$input->get->price_min.'"/>
  <input type="number" name="price_max" id="search_price_max" style="width:80px" placeholder="Maximum" value="'.$input->get->price_max.'"/>
  <select name="currency" id="search_currency">';
foreach($pages->get('name=currency, parent.name=options')->children() as $i) {
  $form .= '<option value="'.$i->title.'">'.$i->title.'</option>';
}
$form .= '</select>
  </p>';

$form .= '<p>
  <label>Length (feet)</label>
  <input type="number" name="length_min" id="search_length_min" style="width:50px" placeholder="Min." value="'.$input->get->length_min.'"/>
  <input type="number" name="length_max" id="search_length_max" style="width:50px" placeholder="Max." value="'.$input->get->length_max.'"/>
  </p>';

$sidebar .= '<form id="boat_search" method="get" action="'.$pages->get("template=listings")->url.'">
  <h2>Search Listings</h2>'
    .$form.
  '<input type="submit" id="search_submit" value="Search"/>
  </form>';
// add reset/clear button
$sidebar .= '<br>'.implode('<br>', array_filter($selected));

$results = $pages->find($selector);
foreach($results as $i) {
  $content .= '<h3>'.$i->title.'</h3> ';
}
$content = "<ol>$content</ol>";

$content .= $results->renderPager(array(
    'nextItemLabel' => "Next",
    'previousItemLabel' => "Prev",
    'listMarkup' => "<ul class='MarkupPagerNav'>{out}</ul>",
    'itemMarkup' => "<li class='{class}'>{out}</li>",
    'linkMarkup' => "<a href='{url}'><span>{out}</span></a>",
    'numPageLinks' => 999,
));

This produces accurate search results and paginates effectively without searching; but the search results don't paginate. When the search results overflow a single page, and you go to page 2, it just shows the default second page of all the original results, no search filter. How do I paginate the search results?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.