I doubt there is a module for this, but hey. Do not let that bring you down, it's actually a great idea for a custom module! If you have a bit of patience, Drupal is very easy to learn once you get past the initial learning curve.
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:
super_usernames.info
and super_usernames.module
. The info
file is very easy:
name = Super Usernames
description = Gives special credits to usernames depending on number of posts.
core = 7.x
files[] = super_usernames.module
The module file would need at the minimum just one hook to be defined. Hooks are just plain old php functions that use a simple naming convention in order to be executed by Drupal automatically.
The hook you need here is hook_node_view
. Basically you want to add :
/*
* 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. After doing this, all your nodes should contain the dynamic value of the number of nodes posted by that node's author. This would be added on the fly on every page load from content-types articles, and pages.
You still need to have it displayed somewhere, though! This is where you would ideally create a sub-theme (so as not to hack a base theme). But for the purpose of this post, we will simply modify one file: node.tpl.php.
Check the theme you are using, by default it is bartik but the procedure is mostly the same whatever theme you are using.
Go into your themes/bartik/templates directory, open the node.tpl.php file. Locate where you want to add the super username in the html, and add this code snippet:
<?php if ($node->super_username): ?>
<div class="superUsername">
<?php print $node->super_username; ?>
</div>
<?php endif; ?>
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.
Hope this doesn't sound too complicated, it's actually quite trivial when you go through the process a few times. Feel free to message me or repost here if you need any help.
Happy coding, cheers!
- PS: This code has been slapped up from memory, nothing is tested but should be pretty close to a fully working example. Your mileage may vary, there may be typos in there.