Skip to main content
added 53 characters in body
Source Link
stefgosselin
  • 3k
  • 1
  • 25
  • 36
/*
 * Implements hook_node_load
 */
function super_usernames_node_view($node, $view_mode){
  $supported_node_types = array('page', 'article', 'blog'); // Supports default content types
  if (in_array($node->type, $supported_node_types) { 
    // query to get number of nodes this user has published
    $result = db_query("SELECT count(nid) as nodecount from {node} WHERE uid = %d", $node->uid);
     $row = db_fetch_object($result); 
     $node_count = $row->nodecount; // Easier to read
     switch ($node_count){
       case $node_count >= 50:
           $node->super_username = "God";
         break;
       case $node_count >= 20:
          $node->super_username = "Super Poster";
         break; 
       case $node_count >= 10:
          $node->super_username = " Frequent Poster";
         break;
       case  $node_count >= 1:  // same as > 0, but who cares...
           $node->super_username = "Poster";
         break;
       case $node_count = 0default:
           $node->super_username = "Noobie";
         break;   // Last break not really needed ...                  
     }
  }
}

Now. One last step, you may need to clear the cache for changes to take effect. Devel moduleDevel module makes it easy, or else just use the sql shown on the pageDrush makes it even easier. After this, you should have your super usernames dynamically shown on all the content-types defined in the supported_node_types array.

/*
 * Implements hook_node_load
 */
function super_usernames_node_view($node, $view_mode){
  $supported_node_types = array('page', 'article', 'blog'); // Supports default content types
  if (in_array($node->type, $supported_node_types) { 
    // query to get number of nodes this user has published
    $result = db_query("SELECT count(nid) as nodecount from {node} WHERE uid = %d", $node->uid);
     $row = db_fetch_object($result); 
     $node_count = $row->nodecount; // Easier to read
     switch ($node_count){
       case $node_count >= 50:
           $node->super_username = "God";
         break;
       case $node_count >= 20:
          $node->super_username = "Super Poster";
         break; 
       case $node_count >= 10:
          $node->super_username = " Frequent Poster";
         break;
       case  $node_count >= 1:  // same as > 0, but who cares...
           $node->super_username = "Poster";
         break;
       case $node_count = 0:
           $node->super_username = "Noobie";
         break;   // Last break not really needed ...                  
     }
  }
}

Now. One last step, you may need to clear the cache for changes to take effect. Devel module makes it easy, or else just use the sql shown on the page. After this, you should have your super usernames dynamically shown on all the content-types defined in the supported_node_types array.

/*
 * Implements hook_node_load
 */
function super_usernames_node_view($node, $view_mode){
  $supported_node_types = array('page', 'article', 'blog'); // Supports default content types
  if (in_array($node->type, $supported_node_types) { 
    // query to get number of nodes this user has published
    $result = db_query("SELECT count(nid) as nodecount from {node} WHERE uid = %d", $node->uid);
     $row = db_fetch_object($result); 
     $node_count = $row->nodecount; // Easier to read
     switch ($node_count){
       case $node_count >= 50:
           $node->super_username = "God";
         break;
       case $node_count >= 20:
          $node->super_username = "Super Poster";
         break; 
       case $node_count >= 10:
          $node->super_username = " Frequent Poster";
         break;
       case  $node_count >= 1:  // same as > 0, but who cares...
           $node->super_username = "Poster";
         break;
       default:
           $node->super_username = "Noobie";                  
     }
  }
}

Now. One last step, you may need to clear the cache for changes to take effect. Devel module makes it easy, Drush makes it even easier. After this, you should have your super usernames dynamically shown on all the content-types defined in the supported_node_types array.

Fixed code example
Source Link
stefgosselin
  • 3k
  • 1
  • 25
  • 36
/*
 * Implements hook_node_load
 */
function super_usernames_node_view($node, $view_mode){
  $supported_node_types = array('page', 'article', 'blog'); // Supports default content types
  if (in_array($node->type, $supported_node_types) { 
    // query to get number of nodes this user has published
    $result = db_query("SELECT count(nid) as nodecount from {node} WHERE uid = %d", $node->uid);
     $row = db_fetch_object($result); 
     $node_count = $row->nodecount; // Easier to read
     switch ($node_count){
       case $node_count =>= 050:
           $node->super_username = "Noobie";"God";
          break;
       case  $node_count >= 120:  // same as > 0, but who cares...
           $node->super_username = "Poster";"Super Poster";
         break; 
       case $node_count >= 10:
          $node->super_username = " Frequent Poster";
         break;
       case  $node_count >= 201:  // same as > 0, but who cares...
           $node->super_username = "Super Poster";"Poster";
         break; 
       case $node_count >== 500:
           $node->super_username = "God";"Noobie";
         break;   // Last break not really needed ...                  
     }
  }
}
/*
 * Implements hook_node_load
 */
function super_usernames_node_view($node, $view_mode){
  $supported_node_types = array('page', 'article', 'blog'); // Supports default content types
  if (in_array($node->type, $supported_node_types) { 
    // query to get number of nodes this user has published
    $result = db_query("SELECT count(nid) as nodecount from {node} WHERE uid = %d", $node->uid);
     $row = db_fetch_object($result); 
     $node_count = $row->nodecount; // Easier to read
     switch ($node_count){
       case $node_count = 0:
           $node->super_username = "Noobie";
          break;
       case  $node_count >= 1:  // same as > 0, but who cares...
           $node->super_username = "Poster";
         break;
       case $node_count >= 10:
          $node->super_username = " Frequent Poster";
         break;
       case $node_count >= 20:
          $node->super_username = "Super Poster";
         break; 
       case $node_count >= 50:
          $node->super_username = "God";
         break;   // Last break not really needed ...                  
     }
  }
}
/*
 * Implements hook_node_load
 */
function super_usernames_node_view($node, $view_mode){
  $supported_node_types = array('page', 'article', 'blog'); // Supports default content types
  if (in_array($node->type, $supported_node_types) { 
    // query to get number of nodes this user has published
    $result = db_query("SELECT count(nid) as nodecount from {node} WHERE uid = %d", $node->uid);
     $row = db_fetch_object($result); 
     $node_count = $row->nodecount; // Easier to read
     switch ($node_count){
       case $node_count >= 50:
           $node->super_username = "God";
         break;
       case $node_count >= 20:
          $node->super_username = "Super Poster";
         break; 
       case $node_count >= 10:
          $node->super_username = " Frequent Poster";
         break;
       case  $node_count >= 1:  // same as > 0, but who cares...
           $node->super_username = "Poster";
         break;
       case $node_count = 0:
           $node->super_username = "Noobie";
         break;   // Last break not really needed ...                  
     }
  }
}
added 29 characters in body
Source Link
stefgosselin
  • 3k
  • 1
  • 25
  • 36

If you need a start, the [module developper section[(http://drupal.org/developing/modules)module developper section and the create a module page on Drupal are great place to start.

There are many, many ways you could do this, but to start I would probably create a small module let<s say. Imagine it's called super_usernames, for the purpose of this post. I would just create a folder in sites/all/modules called `super_usernames. That folder would need to contain only 2 files:

If you need a start, the [module developper section[(http://drupal.org/developing/modules) and the create a module page on Drupal are great place to start.

There are many, many ways you could do this, but to start I would probably create a small module let<s say it's called super_usernames. I would just create a folder in sites/all/modules called `super_usernames. That folder would need to contain only 2 files:

If you need a start, the module developper section and the create a module page on Drupal are great place to start.

There are many, many ways you could do this, but to start I would probably create a small module. Imagine it's called super_usernames, for the purpose of this post. I would just create a folder in sites/all/modules called `super_usernames. That folder would need to contain only 2 files:

Source Link
stefgosselin
  • 3k
  • 1
  • 25
  • 36
Loading