I want to incorporate a given user's blog into his/her profile. In lieu of a link to $user's blog, I want to display their blog entries in the profile itself.

I've tried hacking the blog.module to create a custom function I can call in my template (user_profile.tpl.php) to display blog entries on the profile and have gotten nowhere. I can only display a whole node, with blocks and header/footer, but I wish to display the blog data alone.

The userposts.module is close to what I'm going for, thank you Dublin Drupaller for that recommendation. I want to display more than a list of blog titles, however, I want to display the full entries with comment link et. al

Anyone have some suggestions or attempted a similar effort with better results?

Thanks,
Jonathan

Comments

Dublin Drupaller’s picture

Hiya again Jonathan...

Didn't realise you wanted to display the full blogs with comments....

What might be better than just looking at the userposts.module..is to look at the collimator.module...without getting too complicated, a combination of those modules should do what you want...

i.e. set the collimator module up and "call" it from your user_profile.tpl.php file...in the appropriate place..or call it into an iframe as you mentioned earlier....

Hope that helps and if you have any success please post back up here..I'll be attacking something similar soon..

More info on the collimator.module can be found here..

http://drupal.org/node/8153

cheers

Dub

DUBLIN DRUPALLER
___________________________________________________
A drupal user by chance and a dubliner by sheer luck.
Using Drupal to help build Artist & Band web communities.

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

dumpyfrog’s picture

I figured it out, hallelujah! Let me see if I can trace all the steps...

In the blog.module, I created a new function, "profile_blog($uid)." It's almost identical to the "blog_page_user($uid)" function with one vital exception. print theme('page', $output, $title); has been changed to print theme('blog', $output, $title); That's because I don't want to run it through the page theme with the blocks and the header and footer, I want a stripped down theme that will just show the blog content.

/*The new function in the blog.module to generate blog data for the profile*/

profile_blog($uid) {
  $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));

  if ($account->uid) {
    $title = t("%name's blog", array('%name' => $account->name));
    $output = '';

    $result = pager_query('SELECT DISTINCT(n.nid), n.sticky, n.created FROM {node} n '. node_access_join_sql() ." WHERE type = 'blog' AND n.uid = %d AND n.status = 1 AND ". node_access_where_sql() .' ORDER BY n.sticky DESC, n.created DESC', variable_get('default_nodes_main', 10), 0, NULL, $account->uid);
    while ($node = db_fetch_object($result)) {
      $output .= node_view(node_load(array('nid' => $node->nid)), 1);
    }
    $output .= theme('pager');
    $output .= theme('xml_icon', url("blog/feed/$account->uid"));
    print theme('blog', $output, $title);
  }
  else {
    drupal_not_found();
  }
}

Then I add the function "phptemplate_blog" to the phptemplate.engine, which only displays the content element of the template file and looks like this:

/*The new function in phptemplate.engine theme the stripped down blog data*/

function phptemplate_blog($content) {
  $vars = array(
    'content'             => '<!-- begin content -->' . $content . '<!-- end content -->',
  );
  return _phptemplate_callback('blog', $vars);
}

Then of course I had to create a blog.tpl.php file which very simply looks like this:

<?php print($content) ?>

So in my "user_profile.tpl.php" I call <?php profile_blog($user->uid) ?> and voila! Please, please contact me if this helps or if--more likely with my luck--it doesn't work for you.

Thanks again, Dublin, for your assistance in this matter. Drupal is amazing. I hope I can harness the power of this beast in the coming weeks. All the best,

Jonathan

Dublin Drupaller’s picture

Fair play to ya Jonathan..

Will try your code when i get a spare moment. Had a quick scan and all looks good.

it's a great eye-opener when you discover the immense potential of drupal when you do something like this. for someone like me that is not familiar or an expert in php or mysql.....the combination of drupal with the phptemplate system is incredibly powerful and if I'm able to get my head around it...it is within everyones reach..

Suggest you post a book page here Jonathan...your override is a very good and useful one...I think others will also find it useful as a reference when building their own overrides.

http://drupal.org/node/11811

(Add a CHILD PAGE as opposed to a comment)

Cheers

Dub

DUBLIN DRUPALLER
___________________________________________________
A drupal user by chance and a dubliner by sheer luck.
Using Drupal to help build Artist & Band web communities.

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate