Hello,

I need help to include some nodeprofile cck fields at the top of users blog. It will be used to put some infos about the author before his content.

I guess I have to work with a page-blog.tpl.php , but I don't know how to grab he nodeprofile field...

I also have to say that I'm a real dummy about php : I can copy & paste and adapt a bit, but that's all :)

Does someone has a suggestion ?

Thanks a lot.

Comments

pacome’s picture

just a post to bring this question back on the table :)

pacome’s picture

Here is a first step : I did a node-blog.tpl.php file with the following code in it (directly form the nodeprofile readme file... ooops !)

 $output = nodeprofile_show_profiles($uid);
     echo drupal_render($output);

It works, but too much : It prints the nodeprofile for each post !
I have to find a solution to display it only once, at the top of the page...

[edit] I think it's maybe because I used node-blog.tpl.php : I think it apply its content to every blog post (??)
So maybe the solution would be to put this code directly into page.tpl.php.
I've tried out, but it doesn't display anything... Any idea ?

pacome’s picture

A friend found a solution : he used a page-blog.tpl.php file, wich set the whole page.
The file node-blog.tpl.php set each blog post, because each of them is a node... (of course !)

Here is the code we finaly use in page-blog.tpl.php :

 if (arg(0) == 'blog') {
                $o = array();
                $o[$type] = array(
		                  '#type' => 'nodeprofile_display_full',
			          '#title' => ' ', 
			          '#tabs' => ' ', 
			          '#uid' => arg(1),
			          '#content_type' => 'your-content-type-name',
			          '#weight' => 0,
			          '#suffix' => ' ',
			   );
		print drupal_render($o);
				
              }
       

And it works : we have the nodeprofile at the top of the blog page, with only the cck fields, and without the generic title..

leanazulyoro’s picture

von-p, thas code renders the entire noprofile node, i thought you ere after rendering a cck field that is inside that nodeprofile, have you achived that?

pacome’s picture

Hello Leanazulyoro, yes it print all the nodeprofile node ; it works, but it's not a clean solution..

I don't know how to render a specific field from a cck content (and especially from nodeprofile), and I would really appreciate to find a way to do it. For exemple, I need to do that to customize a blogger block list (from blogger module), and to display the 'name' field from nodeprofile instead of the username. (http://drupal.org/node/229760)

If you know something about that, please let me know !

leanazulyoro’s picture

I have just posted a more general aproach of this post in the cck issues (http://drupal.org/node/235048).
There i ask for a way of printing out a cck field from an specific node into another node. this way we should be able to reference that "specific node" to be the nodeprofile of the author of the node in which we plan to print the field.

leanazulyoro’s picture

von-p, i have a found a way around to do this, but i'm not an advanced drupal developer and the solution involves extracting the desired data directly from the database tables. So i share this solution but still wait for someone who can show us the "drupal" way of doing this.

This is what i've done:

// select the node id of the node used as nodeprofile (where "nodeprofile" is the machine-readable name of the type you used as nodeprofile)
// we'll use it to make another query to a table where the desired field is recorded
$nodeprofile = db_fetch_object(db_query('SELECT nid FROM {node} WHERE uid = %d and type = "nodeprofile"', $node->uid)); 

// now we make another query from the table "content_type_nodeprofile" (again, where nodeprofile is the machine readable name of the 
// type you used as nodeprofile, you should check out the exact names of the tables through phpmyadmin just to be sure) using the node id // previously retrieved.
// here i use an imagefield as an example 
$logo = db_fetch_object(db_query('SELECT field_logo_title FROM {content_type_nodeprofile} WHERE nid = %d', $nodeprofile ->nid));
$rows = db_num_rows(db_query('SELECT field_logo_title FROM {content_type_empresa} WHERE nid = %d', $nodeprofile->nid));

// now print the extracted data ('logo.png' in my example) formated as nessesary:
// as i'm tring to print an image, i should include in the print an <img/> with the appropiate path in the src attribute
if ($rows != 0){
print ' - <img src="' . base_path() . 'files/images/'.$logo->field_logo_title . '" />';
}

PD: well this is my way of doing this, i repeat that i'm still waiting for a drupal way of doing this. i'm not a expert in php and mysql, probable someone with more experience could have done the same i did using only one sql query, so enhanments are welcome.

pacome’s picture

I found something here : http://drupal.org/node/171160 and here : http://drupal.org/node/232427

The first one seems to be for a more general purpose (to put a cck field in page.tpl.php), so it should be almost the same for a page-blog.tpl.php.... Maybe it is the "drupal way" to do it, that you were talking about ?

The second one is more specific (printing a cck field in a calendar) so there is maybe a starting point about my blogger block list.
I will try that..

pacome’s picture

Solution is to use Views + arguments, see : http://groups.drupal.org/node/18382#comment-63301

greetings!

-P-