function phptemplate_username($object){if($object->uid && $object->name){// Shorten the name when it is too long or it will break many tables.if(drupal_strlen($object->name) > 20){$name = drupal_substr($object->name, 0, 15) .'...';
}else{$name = $object->name;
}if($object->fullname){if(drupal_strlen($object->fullname) > 20){$name = drupal_substr($object->fullname, 0, 15) .'...';
}else{$name = $object->fullname;
}}if(user_access('access user profiles')){$output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
}else{$output = check_plain($name);
}}elseif($object->name){// Sometimes modules display content composed by people who are// not registered members of the site (e.g. mailing list or news// aggregator modules). This clause enables modules to display// the true author of the content.if($object->homepage){$output = l($object->name, $object->homepage);
}else{$output = check_plain($object->name);
}$output .= ' ('. t('not verified') .')';
}else{$output = variable_get('anonymous', t('Anonymous'));
}return$output;
}
ผมไม่ได้ลองจริง แต่น่าจะทำงานได้ตามทฤษฎี
»
Submitted by Blue Rabbit on 21 June, 2007 - 16:04.
function phptemplate_username($object){if($object->uid && $object->name){// Shorten the name when it is too long or it will break many tables.if(drupal_strlen($object->name) > 20){$name = drupal_substr($object->name, 0, 15) .'...';
}else{$name = $object->name;
}$profile = user_load(array('uid' => $object->uid));
if($profile->fullname){if(drupal_strlen($profile->fullname) > 20){$name = drupal_substr($profile->fullname, 0, 15) .'...';
}else{$name = $profile->fullname;
}}if(user_access('access user profiles')){$output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
}else{$output = check_plain($name);
}}elseif($object->name){// Sometimes modules display content composed by people who are// not registered members of the site (e.g. mailing list or news// aggregator modules). This clause enables modules to display// the true author of the content.if($object->homepage){$output = l($object->name, $object->homepage);
}else{$output = check_plain($object->name);
}$output .= ' ('. t('not verified') .')';
}else{$output = variable_get('anonymous', t('Anonymous'));
}return$output;
}
»
Submitted by Blue Rabbit on 21 June, 2007 - 21:41.
ปกติ Drupal ไม่ได้เก็บชื่อเต็ม ถ้าอยากให้เก็บต้อง
phptemplate_username($object)ในtemplate.phpในไดเรกทอรีของ themeผมไม่ได้ลองจริง แต่น่าจะทำงานได้ตามทฤษฎี
ผมลองแล้วยังไม่ได้ครับ
สร้างฟังก์ชันนี้ใน template.php แล้ว
ต้องแก้ไขใน node.tpl.php ด้วยหรือไม่ครับ
><?php print $submitted?></blockcode>ใช้โมดูล profile หรือยังครับ เพิ่มฟิลด์ชื่อ fullname
ใช้แล้วครับ

แล้วมีวิธีเรียก ชื่อเต็ม (ค่าในฟิลด์ fullname) มาแสดงใน node.tpl.php โดยไม่ต้องเพิ่มฟังก์ชันใน template.php ได้มั้ยครับ
ที่แท้ผมดูผิดนี่เอง
$objectคือ$nodeนี่นาใช้ได้แล้วครับ... ขอบคุณมากๆ ครับ
เขียนสดรึนี่!!
ผมสงสัยว่าทำไมเราเช็คความยาวที่ 20 แต่ substr ที่ 15
เพราะมันใส่
...ข้างหลังแล้วก็เผื่อโน่นเผื่อนี่อีก 2 ตัวไม่ได้เขียนสดทั้งหมดหรอก เอามาจาก
theme_username()แล้วเพิ่มเข้าไปอีกไม่กี่บรรทัดขอบคุณหลายๆ ครับ แล้วจะลองดู