Question: Our new D7 site was running very slowly so I did some profiling with devel/xhprof and found that D7 was doing millions of preg\_grep function calls within drupal\_find\_theme\_functions() in theme.inc. This happened on every page load.

It's my understanding that the drupal\_find\_theme\_functions function should only be called when the theme registry is being rebuilt - am I correct in that?

I made sure that "rebuild theme registry" was off in devel, and then disabled devel entirely. However, I'm still seeing those millions of function calls to preg\_grep in drupal\_find\_theme\_functions on every page load (I added a piece of code to theme.inc to log when the function was called).

We're using a theme based on Omega and if we are rebuilding the theme registry each time I'm not seeing how/why it's happening. We're turning off as many contrib modules as we can in the meantime. Any help/advice would be MUCH appreciated!!

Answer: 
You can have full control over the taxonomy/term/ID page by intercepting the menu call with hook\_menu\_alter() and let the content be generated by a custom function.

This allows you to completely customize the taxonomy term page. You can check for a certain vocabulary ("Authors") and have a custom generated page for that vocab and leave the others untouched.

You can have fine grained control over how results are displayed using view modes and templates.

No contributed modules are needed.

Here is an example to be used in a custom module. The custom content is generated using Drupals [EntityFieldQuery](https://api.drupal.org/api/drupal/includes!entity.inc/class/EntityFieldQuery/7) because it is a lazy and robust way of generating a list of content, but anything goes here.
.

```
/**
 * * Implements hook_menu_alter(). 
 */
function YOURMODULE_menu_alter(&$menu) {
  if (isset($menu['taxonomy/term/%taxonomy_term'])) {
    $menu['taxonomy/term/%taxonomy_term']['page callback'] = 'YOURMODULE_taxonomy_term_page';
    $menu['taxonomy/term/%taxonomy_term']['access arguments'] = array(2);
  }
}

/**
 * Callback function for taxonomy/term/%taxonomy_term. 
 * 
 * @param $taxonomy_term object
 * @return * Themed page for a taxonomy term, specific to the term's vocabulary. 
 */
function YOURMODULE_taxonomy_term_page($term) {
  $voc = taxonomy_vocabulary_load($term->vid);
  switch ($voc->machine_name) {

    case 'SOMEVOCUBALARY':

      // here you generate the actual content of the page
      // could be done e.g. with an entityfieldquery as follows

      $query = new EntityFieldQuery();
      $query->entityCondition('entity_type', 'node')
              ->fieldCondition('field_gallery', 'tid', $term->tid)
              ->propertyOrderBy('sticky', 'DESC')
              ->propertyCondition('status', 1);
      $result = $query->execute();
      if (!empty($result['node'])) {
        $build['content']['nodes'] = node_view_multiple(node_load_multiple(array_keys($result['node'])), 'teaser'); // output the node teasers. you can control the markup of the 'teaser' view mode with a template in the theme folder
      } else {
        $build['content']['status']['#markup'] = t('No results found for term ID !tid.', array('!tid' => $term->tid));
      }
      return $build;

    // If the term page is for an other vocabulary then use Drupal's default taxonomy page 
    default: 
      module_load_include('inc', 'taxonomy', 'taxonomy.pages');
      return taxonomy_term_page($term);
  }
}

```
Each term has link taxonomy/term/TERM\_ID and if you want vocabulary based theme(customize HTML markup) on terms pages then you can use "Taxonomy Views Integrator" module.

On particular vocabulary edit page you can select views template.
And in that views template you can write customize html so, that pages with taxonomy/term/TERM\_ID get themed.