Drupal quick fixes

Views arguments

Use url arguments to limit views by taxonomy on term pages

If you are on a taxonomy page, with a known term, we can use views2 arguments. Use the following snippet to perform this task.
First add an argument “Taxonomy: term id” and add the following code in the textarea:

  1. tid);
  2. ?>

Use url arguments to limit views by taxonomy on node pages

On node pages, we can use the node id to return taxonomy term id arguments. With these arguments the sql is limited to the returned tids.
First add an argument “Taxonomy: term id” and add the following code in the textarea:

  1. $arg_1 = arg(1);
  2. if ((arg(0) == ‘node’) && (is_numeric($arg_1))) {
  3.   $tax_node = node_load($arg_1);
  4.   $tids = array_keys($tax_node->taxonomy);
  5.   // here you could hardcoded test on a vocab id if you wish:
  6.   /*
  7.   foreach ($node->taxonomy AS $tid => $term) {
  8.      if ($term->vid == $vid) $tids[] = $tid;
  9.   }*/
  10.   $args = $tids;
  11. }
  12. return isset($args[0]) ? $args[0] : 0;

Various fixes

Hide tabs on node form pages, except for certain roles

  1. uid == 1) || in_array(‘redactie’, array_values($user->roles)) || in_array(‘webmaster’, array_values($user->roles))) { ?>

Log next page with google analytics

  1. function logOutgoingUrl(a) {
  2.   pageTracker._trackPageview(‘/outgoing/’+a);
  3.   $.ajax({
  4.    type: "POST",
  5.    url: "/log/exiturl",
  6.    data: "url=" + a,
  7.    success: function(msg){
  8.      window.location = a;
  9.    }
  10.  });
  11.  return false;
  12. }

Create submenu-items from selected menu-item (1 depth)

  1.       $menu_item = menu_get_item();
  2.       $menu_name = db_result(db_query_range("SELECT menu_name FROM {menu_links} WHERE link_path = ‘%s’ ORDER BY mlid ASC", $menu_item[‘href’], 0, 1));
  3.       $menu_tree = menu_navigation_links($menu_name, 1);
  4.  
  5.       $output = ;
  6.  
  7.       if($menu_tree) {
  8.  
  9.         foreach($menu_tree as $link) {
  10.           $menu_link = theme(‘menu_item_link’, $link);
  11.           $output .= theme(‘menu_item’, $menu_link, false);
  12.         }
  13.         $output = theme(‘menu_tree’, $output);
  14.  
  15.       }
  16.       return $output;

This entry was posted on Friday, November 7th, 2008 at 4:11 pm and is filed under quick fixes. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply