You are here

function _taxonomy_menu_page in Taxonomy menu 5

Same name and namespace in other branches
  1. 6 taxonomy_menu.inc \_taxonomy_menu_page()

Page callback that renders a node listing for the selected term.

1 call to _taxonomy_menu_page()
__taxonomy_menu_page in ./taxonomy_menu.module
Page callback that renders a node listing for the selected term.

File

./taxonomy_menu.inc, line 280
taxonomy_menu.inc @author Jonathan Chaffer <jchaffer@structureinteractive.com> @author Bruno Massa <http://drupal.org/user/67164> It Generates menu links for all taxonomy terms

Code

function _taxonomy_menu_page() {

  // Check if the Vocabulary ID is set
  if (($vid = arg(0)) || ($vid = variable_get('taxonomy_menu_hide_module_page', FALSE) ? arg(0) : FALSE)) {

    // Depending on what Output technique is used,
    // show the nodes' list
    if (variable_get('taxonomy_menu_show_' . $vid, TAXONOMY_MENU_NORMAL) == TAXONOMY_MENU_NORMAL) {
      if ($tid = variable_get('taxonomy_menu_hide_module_page', FALSE) ? arg(1) : arg(2)) {
        $tid = explode('/', $_GET['q']);
        $tid = db_escape_string(array_pop($tid));
        $feed = url('taxonomy/term/' . $tid . '/' . (variable_get('taxonomy_menu_display_descendants', TRUE) ? 'all' : 0) . '/feed');
        drupal_add_feed($feed);
        $result = taxonomy_select_nodes(array(
          $tid,
        ), 'or', variable_get('taxonomy_menu_display_descendants', TRUE) ? 'all' : 0);
      }
      else {

        // If no arg(2), we're looking at just the vid. If
        // display_descendants is on, grab all terms regardless
        // of depth. If off, grab depth 0 terms.
        $tree = taxonomy_get_tree($vid);
        $descendants = variable_get('taxonomy_menu_display_descendants', 1);
        foreach ($tree as $term) {
          if ($descendants or $term->depth == 0) {
            $tids[] = $term->tid;
          }
        }

        // The requested terms have already been determined,
        // so don't request descendants here.
        $result = taxonomy_select_nodes($tids, 'or', 0);
      }

      // Render the selected nodes
      $output = taxonomy_render_nodes($result);
    }
    elseif (variable_get('taxonomy_menu_show_' . $vid, TAXONOMY_MENU_NORMAL) == TAXONOMY_MENU_VIEW) {

      // Get the last page argument
      $tid = explode('/', $_GET['q']);
      $tid = db_escape_string(array_pop($tid));
      $arguments[] = $vid;

      // Only add the Term ID if its not the Vocabulary ID
      if ($vid != $tid) {
        $arguments[] = $tid;
      }

      // Embed the views output into the page
      $view = views_get_view(variable_get('taxonomy_menu_show_views_' . $vid, ''));
      $view_empty_text = $view->page_empty;
      if ($view) {

        // set $view->url to current page
        $view->url = $_GET['q'];
        $output = views_build_view('embed', $view, $arguments, $view->use_pager, $view->nodes_per_page);
      }
      else {
        $output = '';
      }
    }
  }

  // If no content found, return a "error" message

  //return empty($output) ? t('No content for this category.') : $output;
  return empty($output) ? $view_empty_text ? $view_empty_text : t('No content for this category.') : $output;
}