0

In Drupal 6 the TVI module had an option: "Display term description" "When enabled, the term description is displayed before the rendered view on term page."

Unfortunately I can't find this option to display the term description on top of views page of taxonomy term in the Drupal 7 version of TVI.

Is there any other way to display the term discription on top of the view (the view displays all content/nodes of the specific term). Thank you.

  • 1
    You should update your question and mention that you are not looking for block-based solutions like Kevin suggested below. It will help other posters come up with a more suitable suggestion to your problem. – Stefanos Petrakis Sep 20 '16 at 7:57
  • 1
    Also, I don't see a possibility for you to get the functionality TVI for D6 offered without some custom coding/theming. There seem to be no site-building options apart from the ones that Kevin suggested below. – Stefanos Petrakis Sep 20 '16 at 8:05
  • I am sure there are a lot of solutions (programming, hook function, and others). I you do not let others to post your own solutions because you say there is not other solution then this is not fair. – drupalfan Sep 20 '16 at 9:41
  • 1
    We agree, there are lot of other solutions, just not site-building ones, that would come as close to #2 below. Are you interested in a custom coding/theming solution? Or are you only looking at site-building options? – Stefanos Petrakis Sep 20 '16 at 9:47
  • 1
    Because it's not clear if you are looking for a site-building or a coding solution. Below is an alternative answer with coding. – Stefanos Petrakis Sep 20 '16 at 11:40
1

Here is a coding solution, I still find the suggestion from Kevin to be 'cleaner'/'easier'.
Still, for what it's worth:

function YOURMODULE_preprocess_views_view(&$vars) {
  if( $vars['name'] == 'taxonomy_term' && $vars['display_id'] == 'page' ){  
    $term = menu_get_object('taxonomy_term', 2);
    $term_description = array(
      '#markup' => check_markup($term->description, $term->format, '', TRUE),
      '#prefix' => '<div class="taxonomy-term-description">',
      '#suffix' => '</div>',
    );  
    $vars['header'] = drupal_render($term_description) . $vars['header'];
  }
}

You should modify the condition(s) to match your view and display. The rest of the code is copied from the taxonomy_term_build_content() function of the core taxonomy module.

You should also note that the description is prepended to whatever content is already present in the header variable.

Good luck!

|improve this answer|||||
  • Thank you. I will try this. Is this code similar to the code in Drupal 6 version of TVI module? – drupalfan Sep 20 '16 at 12:11
  • As much as possible, yes. It's a bit more structured, as it targets the header variable. The TVI in D6 was concatenating the view's preview output with the term's description. – Stefanos Petrakis Sep 20 '16 at 12:16
1

I haven't used Drupal 6 since 2010, so I can't speak to what used to be.

There are a few options here, given the differences in Views for 7/8 vs 6.

  1. You can attach a field in the view header for the term description.
  2. You can create a separate block display, and put that block on any term path.

I usually opt for #2, so I can put the term description and term name in a hero region, and keep the main view output uncluttered. Although you can use TVI in various ways, I stick to creating taxonomy/term/% as the page paths so feeding arguments so it is simple. So for the block, create a contextual filter and feed it the taxonomy term ID from URL.

You could also have the view render the term as a view mode as well, instead of fields. It's pretty flexible.

edit: The reason it shows without using TVI or Views is because the page callback for a term path hardcodes and prepends it: https://api.drupal.org/api/drupal/modules!taxonomy!taxonomy.pages.inc/function/taxonomy_term_page/7.x .

That is one of a handful of reasons modules like TVI were created in the first place, so you can arrange your own display(s). Since TVI is injecting a View, it does not hardcode anything into the output:

/**
 * Replace taxonomy page callback.
 *
 * If more or less than one term is given then pass the request off
 * to the original taxonomy module page callback.
 *
 * @param int|object $tid
 *   The term tid or the term object.
 * @param null|int $depth
 *   The shown depth.
 *
 * @return array
 *   The build array.
 */
function tvi_render_view($tid, $depth = NULL) {
  if (is_object($tid)) {
    $tid = $tid->tid;
  }

  list($view, $display, $term, $settings) = tvi_get_view_info($tid);
  // Load metatags if needed.
  if (module_exists('metatag')) {
    metatag_entity_view($term, 'taxonomy_term', 'full', NULL);
  }
  if (is_object($view) && $display) {
    $output = t('There was no content found matching this term.');

    if (isset($settings->pass_arguments) && $settings->pass_arguments == 1) {
      // Pass all arguments to views. Exclude /taxonomy/term.
      $args = array_slice(arg(), 2);
    }
    else {
      $args = array($tid);
      if (NULL !== $depth) {
        $args[] = $depth;
      }
    }

    if ($view->display[$display]->display_plugin == 'block') {
      // If it's a block display, views returns a block array which won't work
      // as a page callback so we need to explicitly set the page title
      // and just return the $block['content'].
      $block = $view->execute_display($display, $args);
      drupal_set_title($block['subject']);
      $output = $block['content'];
    }
    else {
      global $language;
      module_invoke_all('entity_view', $term, 'taxonomy_term', 'full', $language->language);
      $output = $view->execute_display($display, $args);
    }

    return $output;
  }

  // Taxonomy is last resort - used if no standard views are found.
  module_load_include('inc', 'taxonomy', 'taxonomy.pages');
  return taxonomy_term_page($term);
}

This is easily solvable in a few minutes with either solution above.

|improve this answer|||||
  • Thank you for your answer. But this is not what I want to do. On /taxonomy/term/xx/edit you can change the terms name and description. I want that exactly this description of each therm will be display on each correspondig term page /taxonomy/term/xx on top of view. And this should work automatically whithout andy extra view or blocks. If you do not override the original taxonomy term page display (not with TVI and not with a special overridig view) then also the term descreption os displayd. The same way I want to have it using TVI. – drupalfan Sep 19 '16 at 22:22
  • 1
    @drupalfan: The block solution (#2) is your best bet at the moment, and is a straightforward solution, as far as site-building options go. – Stefanos Petrakis Sep 20 '16 at 8:04
  • #2 does not use term descriptions from /taxonomy/term/xx/edit, so it es not a suitable solution. – drupalfan Sep 20 '16 at 9:39
  • Creating a block of a term from term argument can show any field on that term, so I don't understand what you mean. – Kevin Sep 20 '16 at 11:49

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.