3

I'm working in Drupal 7.

I have an issue with the search results: I have many records, and only one page with 10 results is generated. If I do a search that have many results (e.g. 50 results) I always see a single page showing 10 results.

If I change the template of a core module, e.g. the Garland theme, the pagination works well; if I set as default the custom template, the pagination doesn't work. In a template what calls the pagination? Why doesn't the pagination work in the custom template?

The custom template is based on a contributed theme. If I remove the search--results.tpl.php file, I see the pagination, but only two pages for any search. If a search returns 50 results, I can only see two pages; if the search only has one result, I can only see two pages showing the same result duplicated more than once.

The code contained in the search--results.tpl.php file is the following one.

<?php if ($search_results): ?>
  <h2><?php print t('Search results');?></h2>
  <ol class="search-results <?php print $module; ?>-results">
    <?php print $search_results; ?>
  </ol>
  <?php 
       /* $search_conf = variable_get('search_config','');
        $search_limit = $search_conf['results']['limit']; */

  if (stripos($pager,'page=2')) print $pager; ?>
<?php else : ?>
  <h2><?php print t('Your search yielded no results');?></h2>
  <?php print search_help('search#noresults', drupal_help_arg()); ?>
<?php endif; ?>

The content of the template.php file is the following one.

/**
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return a string containing the breadcrumb output.
 */
function MYTHEME_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];

  if (!empty($breadcrumb)) {
    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';

    $output .= '<div class="breadcrumb">' . implode(' › ', $breadcrumb) . '</div>';
    return $output;
  }
}

/**
 * Override or insert variables into the maintenance page template.
 */
function MYTHEME_preprocess_maintenance_page(&$vars) {
  // While markup for normal pages is split into page.tpl.php and html.tpl.php,
  // the markup for the maintenance page is all in the single
  // maintenance-page.tpl.php template. So, to have what's done in
  // MYTHEME_preprocess_html() also happen on the maintenance page, it has to be
  // called here.
  MYTHEME_preprocess_html($vars);
}

/**
 * Override or insert variables into the html template.
 */
function MYTHEME_preprocess_html(&$vars) {
  // Toggle fixed or fluid width.
  if (theme_get_setting('MYTHEME_width') == 'fluid') {
    $vars['classes_array'][] = 'fluid-width';
  }

  $vars['node_type_MYTHEME'] = '';
  if ($node = menu_get_object()) {
    $vars['node_type_MYTHEME'] = $node->type; // find your cck field here
  }

  // Add conditional CSS for IE6.
  drupal_add_css(path_to_theme() . '/fix-ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lt IE 7', '!IE' => FALSE), 'preprocess' => FALSE));

}

/**
 * Override or insert variables into the html template.
 */
function MYTHEME_process_html(&$vars) {

  // Hook into color.module
  if (module_exists('color')) {
    _color_html_alter($vars);
  }
}

/**
 * Override or insert variables into the page template.
 */
function MYTHEME_preprocess_page(&$vars) {

    /*if (isset($vars['node'])) {
    $vars['theme_hook_suggestion'] = 'page__'.$vars['node']->type; //
    }*/

    }

/**
 * Override or insert variables into the node template.
 */
function MYTHEME_preprocess_node(&$vars) {

  if(user_is_logged_in() == 0){
  unset($vars['content']['links']['comment']['#links']['comment-add']['title']);
  }

  $vars['submitted'] = $vars['date'] . ' — ' . $vars['name'];

  $type = $vars['type'];

  if ($vars['teaser']) { // custom teaser templates
    $vars['theme_hook_suggestions'][] = 'node__teaser';
  }
  if ($vars['teaser'] && $vars['type']) {
    $vars['theme_hook_suggestions'][] = 'node__' . $type . '__teaser';
  }
}

/**
 * Override or insert variables into the comment template.
 */
function MYTHEME_preprocess_comment(&$vars) {
  $commentsDate = date('M d, Y',$vars['elements']['#comment']->created);
  $vars['submitted'] =  $vars['author'] . ' — ' . $commentsDate;
  //$vars['submitted'] = $vars['author'];
  $vars['title'] = $vars['elements']['#comment']->subject;
}

/**
 * Override or insert variables into the block template.
 */
function MYTHEME_preprocess_block(&$vars) {
  $vars['title_attributes_array']['class'][] = 'title';
  $vars['classes_array'][] = 'clearfix';
}

/**
 * Override or insert variables into the page template.
 */
function MYTHEME_process_page(&$vars) {
  // Hook into color.module
  if (module_exists('color')) {
    _color_page_alter($vars);
  }
}

/**
 * Override or insert variables into the region template.
 */
function MYTHEME_preprocess_region(&$vars) {
  if ($vars['region'] == 'header') {
    $vars['classes_array'][] = 'clearfix';
  }
}

/**
 * Override or insert variables into the region template.
 */
function MYTHEME_form_search_block_form_alter(&$form, &$form_state) {
  $form['actions']['submit']['#type'] = 'image_button';
  $form['actions']['submit']['#src'] = drupal_get_path('theme', 'MYTHEME') . '/images/button-search.png';
}


/**
 * Implement themehook_preprocess_user_picture().
 */
/*function MYTHEME_preprocess_user_picture(&$variables) {
$variables['fpublic_path_image_user'] = $variables['account']->picture->uri;
}*/

/**
 * Implement MYTHEME_node_preview for rewrite related message.
 */

function MYTHEME_node_preview($variables) {
  $node = $variables['node'];

  $output = '<div class="preview">';

  $preview_trimmed_version = FALSE;

  $elements = node_view(clone $node, 'teaser');
  $trimmed = drupal_render($elements);
  $elements = node_view($node, 'full');
  $full = drupal_render($elements);

  // Do we need to preview trimmed version of post as well as full version?
  if ($trimmed != $full) {
    if(!preg_match('@videos|image@',$node->type)){
    drupal_set_message(t('The trimmed version of your post shows what your post looks like when promoted to the list of pages or when exported for syndication.<span class="no-js"> You can insert the delimiter "&lt;!--break--&gt;" (without the quotes) to fine-tune where your post gets split.</span>'));
    }
    if(!preg_match('@videos|image@',$node->type)){
    $output .= '<h3>' . t('Preview trimmed version') . '</h3>';
    $output .= $trimmed;
    }
    $output .= '<h3>' . t('Preview full version') . '</h3>';
    $output .= $full;
  }
  else {
    $output .= $full;
  }
  $output .= "</div>\n";

  return $output;
}



function MYTHEME_form_element_label($variables) {
  $element = $variables['element'];
  // This is also used in the installer, pre-database setup.
  $t = get_t();

  // If title and required marker are both empty, output no label.
  if ((!isset($element['#title']) || $element['#title'] === '') && empty($element['#required'])) {
    return '';
  }

  // If the element is required, a required marker is appended to the label.
  $required = !empty($element['#required']) ? theme('form_required_marker', array('element' => $element)) : '';

  $title = filter_xss_admin($element['#title']);

  $attributes = array();
  // Style the label as class option to display inline with the element.
  if ($element['#title_display'] == 'after') {
    $attributes['class'] = 'option';
  }
  // Show label only to screen readers to avoid disruption in visual flows.
  elseif ($element['#title_display'] == 'invisible') {
    $attributes['class'] = 'element-invisible';
  }

  if (!empty($element['#id'])) {
    $attributes['for'] = $element['#id'];
  }

    if($element['#parents'][0] == 'field_image' && $element['#title'] == 'Title'){
    return ' <label' . drupal_attributes($attributes) . '>' . $t('Image Caption !required', array('!title' => $title, '!required' => $required)) . "</label>\n";
    }   else {
    // The leading whitespace helps visually separate fields from inline labels.
    return ' <label' . drupal_attributes($attributes) . '>' . $t('!title !required', array('!title' => $title, '!required' => $required)) . "</label>\n";
    }
}
  • I put the code that appears in the next page: api.drupal.org/api/drupal/includes!pager.inc/function/… and I changed the THEME_pager() by MYTHEME_pager() and didn't work the code. Thanks for your answer. – cabita Mar 15 '12 at 23:38
  • What theme are you using? If it is custom, is it based on a contributed theme? Do you have search-results.tpl.php in your theme? You do not need this or the THEMENAME_pager() function in your theme, but if you do have them, they may be incorrectly overriding the default behavior and would give a clue as to a possible cause of your issue. – sheena_d Mar 15 '12 at 23:43
  • Thanks. I removed the search--result.tpl.php in my theme and now shows only two pages with results and no more. If I have 200 results only show two pages with 10 results each one. – cabita Mar 16 '12 at 0:00
  • @cabita Do you have any other content on the page that also has a pager? For example a list of content in a block generated by a View? – Clive Mar 16 '12 at 10:44
  • Hi Clive. Thanks for your help. In a block generated by a View the pagination is shown. The pager fails in the coments and the search. – cabita Mar 16 '12 at 11:15
4
+50

In your search-results.tpl.php file you've got this line near the bottom:

if (stripos($pager,'page=2')) print $pager; ?>

That line is definitely not part of the standard search-results.tpl.php and would definitely cause strange issues when outputting the pager.

Try changing that line to simply:

print $pager;

That should solve the problem. :)

  • I want to comment that I have in the theme this file in the folder template_search. When I delete this file the results are always two pages for any search, and if I keep the file in the folder themplate_search, it only shows 10 results without pagination. – cabita Mar 16 '12 at 16:11
  • I did the change and the issues with the search continue. Only show two pages of results. I must to modify directly the search--results.tpl.php in mysite/modules/search/theme? – cabita Mar 16 '12 at 16:34
  • I put this code in the search-results.tpl.php : pastebin.com/r4BaRtNX and flush the cache and the results of the searchs continue showing two pages of results and no more. – cabita Mar 16 '12 at 16:40
  • That's very strange. It sounds like a contributed or custom module that you've got installed is causing the problem...do you have any contributed search modules installed? If so do you know which one(s)? – Clive Mar 16 '12 at 16:47
  • The only module is search configuration, and I have uninstalled and tested and the issue continue. – cabita Mar 16 '12 at 16:55
0

Try this:

  1. edit the the view for block with pagination (you said in a comment that you have such a block);
  2. go to the "pager" section and click on "paged, x items" (x is the number of items you display)
  3. change "pager ID" to a different number
  4. save the view

I think that your block is overriding the main pager. By changing that ID you tell Drupal that it should use 2 different pagers on the same page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.