I have a list of Staff Members in Drupal6.
I need to style a node such that the email field of a staff member displays as "Contact [First word of Full Name field]". Clicking it causes a mailto:// link to open. BTW, I know that's not a recommended procedure because a contact form or a captcha would be more effective, but my client desires it.
Yes, I'm using the CCK module and the CCK Email module too.
So, again, I have a list of staff members using a custom content type. I have an email field in there using CCK Email module. When I display the node of a staff member, it's just showing the email address. My client wants to make it say "Contact Jonathan" if the staff member is named "Jonathan McDaniels", and so on with each node of each staff member. When "Contact Jonathan" or "Contact Sara" is clicked, it should do the ordinary mailto:// hyperlink stuff.
Yet another way to do this is with PHP. You can create a file node.tpl.php in your theme folder, copying this over from the garland theme. At the top of it, however, add this call:
require_once('node_hooks.php');
Now create a file node_hooks.php in your themes folder. This gives you enormous power now over a given node. You should start to learn the $node variable by doing this in your node_hooks.php file:
<?php
print_r($node);
Refresh your node page and then do a View Source in your browser on it. This will show you the object and each array element inside $node.
In my case I had a node of type 'staff' because that's what I called it when creating it. I also had a special CCK field called CCK Email and used it to create a field named field_staff_email. This was storing a value like [email protected]. So, because of this, I could add this into my node_hooks.php file to do the search and replace on the content so that I get "Contact Jonathan" instead of the email address:
<?php
if ($node->type == 'staff') {
adjustStaffContactField($node, $content);
}
function adjustStaffContactField(&$node,&$content) {
$asWords = explode(' ',$node->title);
$sContact = htmlentities(strip_tags($asWords[0]));
$sContact = trim($sContact);
$sContact = "Contact $sContact";
$sLink = $node->field_staff_email[0]['email'];
$sContact = "<a href='mailto:$sLink'>$sContact</a>";
$sLookingFor = "<a href=\"mailto:$sLink\">$sLink</a>";
$content = str_replace($sLookingFor, $sContact, $content);
}