0

I am trying to create an educational website. I have created terms as

History, Science, Biology, Mathematics and Mathematics term, sub-term as Algebra, Trigonometry

I want to create a separate page like frontpage for each term with few posts sticky at top. For example When someone clicks on History then a page with teaser view of Articles like "About history", "Books for history", " Preparation Guide" will be top on that page list and all other nodes tagged with History term will come below these three posts.

And how can I set no of total posts of History term page as 10?

I am new to drupal and not able to find right modules. Stuck in this issue for 2 days, any help will be appreciated.

0

You can create a custom module and implement hook_menu_alter for taxonomy terms.

In your custom callback you then filter by your taxonomy and intercept the ones you want and pass the rest to the default handler.

On the ones that you intercept you then render a custom view for that taxonomy. That view will just be a normal default view (no page) with an attachment as well. You set the attachment to the top of the other view and show teasers. The other view will show links only with an offset to not show the teaser nodes as well. Your view will be constructed with appropriate contextual filters that you will pass.

Your MODULE.module file:

function MODULE_menu_alter(&$items){
  // change taxonomy view path for certain vocabularies
  $items['taxonomy/term/%taxonomy_term']['page arguments'][] =   $items['taxonomy/term/%taxonomy_term']['page callback'];
  $items['taxonomy/term/%taxonomy_term']['page callback'] = 'MODULE_taxonomy_term_callback';
  $items['taxonomy/term/%taxonomy_term']['file path'] = drupal_get_path('module', 'MODULE') . '/includes';
  $items['taxonomy/term/%taxonomy_term']['file'] = 'MODULE_callbacks.inc';
}

Your MODULE_callbacks.inc file (located at MODULE/includes):

function MODULE_taxonomy_term_callback($term, $callback) {
  $function = __FUNCTION__ . '_' . $term->vocabulary_machine_name;
  if (function_exists($function)) {
    return $function($term);
  }

  module_load_include('inc', 'taxonomy', 'taxonomy.pages');
  return $callback($term);
}

// one for each vocabulary
function MODULE_taxonomy_term_callback_TAXONOMYVOCABULARYMACHINENAME($term){
  $view = views_get_view('VIEW_MACHINE_NAME');
  $view->set_display('default');
  $view->set_arguments(array($term->tid));
  $view->pre_execute();
  $view->execute();
  return $view->render();
}

You View(s) will be as follows:

Contextual filter: Content (taxonomy in question)

When the filter value is not available

  • Provide default value: Taxonomy term ID from URL
  • Load default filter from term page.
|improve this answer|||||
  • Will try this and update. – Sam Apr 10 '16 at 7:32

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.