I've created a custom block and set it so it only shows up on nodes that are of the content type "song." The Song content type was created using CCK, and has the standard textfield "field_artist" which is required but not multi-valued.
I want to use PHP in my custom block to display the contents of the CCK field. More specifically, I want the contents of the CCK field to be part of a hyperlink that will be in the block.
This is the relevant code I'm using in the block:
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
$node = node_load(array('nid' => arg(1)));
$artist = $node->field_artist[0];
echo "<a href=\"http://www.amazon.com/gp/search?ie=UTF8&keywords=$artist&tag=bmu0b-20&index=digital-music\">Artist</a>";
}
In the URL that shows up when the block is rendered, the variable $artist just shows up as "Array." That means it's trying to use this:
Array (
0 => [artist]
)
But I want it to render the artist's name - a value from the array, not the whole thing.
Thoughts? Thanks very much!
Comments
I'm pretty sure I know what
I'm pretty sure I know what you're asking, and if so this post helped me out a ton on a similar issue:
http://drupal.org/node/161675
Not really, though it's the
Not really, though it's the same field of thought.
I have
$node->field_artist[0]which displaysarray ( [0] => [value] ). I want to know how I have to change$node->field_artist[0]so that ONLY[value]shows up instead.I'm not entirely sure if
I'm not entirely sure if this will solve the issue, but have you tried:
so in your case it would be:
Wow
$node->field_artist[0]['artist']didn't work, but$node->field_artist[0]['value'](with the literal word "value") did!Thanks very much. My site actually has every single feature it needs now (click on a song and look in the upper-right).
Cool! Glad you got it
Cool! Glad you got it working!
Thanks!
Solving problems is so easy in Drupal because most of the time, someone's already had that problem, asked about it, and gotten it solved!
This is exactly what I needed. Thanks!