हैकिंग कोर के बिना taxonomy_term_page () के आउटपुट को फिर से लिखें


10

Drupal 7 में, taxonomy.pages.inc शामिल है taxonomy_term_page(), जो <div class="term-listing-heading">टैक्सोनॉमी हेडिंग आउटपुट के आसपास है।

मैं अपनी थीम में taxonomy_term_page () के आउटपुट को फिर से कैसे लिख सकता हूं , इसलिए मैं कोर को हैक किए बिना DIV को हटा सकता हूं?

मुझे काफी आश्चर्य है कि वहाँ tpl.php फ़ाइल उपलब्ध नहीं है taxonomy_term_page()क्योंकि यह उनके लिए बहुत आसान बना देगा।


जवाबों:


11

आप इसे प्रीप्रोसेस पेज के साथ कुछ इस तरह से कर सकते हैं:

function themename_preprocess_page(&$vars) {
  if  (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
    unset($vars['page']['content']['system_main']['term_heading']['#prefix']);
    unset($vars['page']['content']['system_main']['term_heading']['#suffix']);
  }
}

अपने विषय में template.php

मेरा मानना ​​है कि system_mainआपकी साइट सेटअप के आधार पर कुछ और कहा जा सकता है।


6

जैसा कि यह एक मेनू कॉलबैक है, आप उस पृष्ठ के लिए लागू मेनू कॉलबैक को बदलने के लिए एक मॉड्यूल में hook_menu_alter () को लागू कर सकते हैं ।

function mymodule_menu_alter(&$items) {
  if (!empty($items['taxonomy/term/%taxonomy_term'])) {
    $items['taxonomy/term/%taxonomy_term']['page callback'] = 'mymodule_term_page';
  }
}

function mymodule_term_page($term) {
  // Build breadcrumb based on the hierarchy of the term.
  $current = (object) array(
    'tid' => $term->tid,
  );
  $breadcrumb = array();

  while ($parents = taxonomy_get_parents($current->tid)) {
    $current = array_shift($parents);
    $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
  }
  $breadcrumb[] = l(t('Home'), NULL);
  $breadcrumb = array_reverse($breadcrumb);
  drupal_set_breadcrumb($breadcrumb);
  drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->name);

  $build = array();

  $build['term_heading'] = array(
    'term' => taxonomy_term_view($term, 'full'),
  );

  if ($nids = taxonomy_select_nodes($term->tid, TRUE, variable_get('default_nodes_main', 10))) {
    $nodes = node_load_multiple($nids);
    $build += node_view_multiple($nodes);
    $build['pager'] = array(
      '#theme' => 'pager', 
      '#weight' => 5,
    );
  }
  else {
    $build['no_content'] = array(
      '#prefix' => '<p>', 
      '#markup' => t('There is currently no content classified with this term.'), 
      '#suffix' => '</p>',
    );
  }
  return $build;
}

धन्यवाद! मुझे googletorp की विधि पसंद है क्योंकि इसे अलग मॉड्यूल की आवश्यकता नहीं है। लेकिन आपका सुझाव बहुत अच्छा है क्योंकि यह अधिक नियंत्रण देता है। धन्यवाद!
— big_smile

जहाँ तक मुझे याद है, hook_menu_alter()एक विषय में भी लागू किया जा सकता है; Drupal 7 में, विषय परिवर्तन हुक लागू कर सकते हैं।
— kiamlaluno

2

पिछले उदाहरण की तरह, इसके अलावा यह मूल फ़ंक्शन को कॉपी करने के बजाय एक आवरण में टैक्सोनॉमी_टरम_पेज से रिटर्न को संशोधित करने के लिए क्लीनर और अधिक भविष्य का प्रमाण हो सकता है:

function mymodule_menu_alter(&$items) {
  if (!empty($items['taxonomy/term/%taxonomy_term'])) {
    $items['taxonomy/term/%taxonomy_term']['page callback'] = '_custom_taxonomy_term_page';
  }
}

function _custom_taxonomy_term_page ( $term ) {

   $build = taxonomy_term_page( $term );

   // Make customizations then return
   unset( $build['term_heading']['#prefix'] ); 
   unset( $build['term_heading']['#suffix'] );

   return $build;
}

यह शायद इसे करने का सबसे अच्छा तरीका है।
— होरेशियो एल्डेरान
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.