When you do a search the results include "Content type" "User" and "Date".

I wanted to remove the "User", so after a lot of searching I found that I needed to add a section of code to my themes (pixture_reloaded) template.php namely

function pixture_reloaded_preprocess_search_result(&$variables) {
  $result = $variables['result'];
  $variables['url'] = check_url($result['link']);
  $variables['title'] = check_plain($result['title']);

  $info = array();
  if (!empty($result['type'])) {
    $info['type'] = check_plain($result['type']);
  }
/*  if (!empty($result['user'])) {
    $info['user'] = $result['user'];
  }
*/
  if (!empty($result['date'])) {
    $info['date'] = format_date($result['date'], 'small');
  }
  if (isset($result['extra']) && is_array($result['extra'])) {
    $info = array_merge($info, $result['extra']);
  }

  // Check for existence. User search does not include snippets.
  $variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
  // Provide separated and grouped meta information..
  $variables['info_split'] = $info;
  $variables['info'] = implode(' - ', $info);
  // Provide alternate search result template.
  $variables['template_files'][] = 'search-result-'. $variables['type'];
}

but for some reason it doesnt appear to work.

This code is essentially is from search.pages.inc of the search module but with "template" in the fuction replaced with "pixture_reloaded" and the code relating to "user" commented out

I also tried this to Garland with no effect. Commenting out in the search.pages.onc file does work so it must be something to do with my code

Any help would be appreciated

Comments

gdoteof’s picture

i have not done anything with this, but I believe what you need to do is look in modules/search/serach-result.tpl.php

it looks like the $info variable has the content type, user, and date in it, and you can use $info_split['type'] and $info_split['comment'] instead of $info, and then you would not have the user.

try replacing

  <?php if ($info) : ?>
  <p class="search-info"><?php print $info; ?></p>
  <?php endif; ?>

with

  <?php if ($info) : ?>
  <p class="search-info"><?php print $info_split['type']; ?></p>
  <?php endif; ?>

in general you should be editing template files rather than functionality to control what is displayed and where

Anonymous’s picture

Many thanks for the reply.

This also worked to remove un-wanted data, unfortunately again it only worked in the modules/search folder.

If i tried to move or copy the search-result-tpl.php to my theme folder it didnt work, neither did a suggestion elsewhere that suggests changing the file to search-result-node.tpl.php

FIXED
I finally got it working. Even though out of habit i save the theme settings it had made no difference, changing the theme and then changing back resulted in the theme seeing the tpl

epersonae2’s picture

The thing that makes it work is clearing the theme registry!