On Feb 7, 2008 2:40 PM, Florian Loretan <<a href="mailto:floretan@gmail.com">floretan@gmail.com</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The $node variable is not defined in hook_block.<br><br>What you need to do is make sure you are indeed on a node page of type<br>"blog", and then load the information from the url in the 'display'<br>section of your hook_block:<br>
<br>if (arg(0) == 'node' && is_numeric(arg(1))) {<br> $node = node_load(array('nid' => arg(1)));<br> if ($node->type == 'blog') {<br> $author = user_load(array('uid' => $node->uid));<br>
$block['subject'] = t('About the author');<br> $block['content'] = theme('username', $author); // do whatever you<br>want to create the content of your block using $node and $author<br>
// ...<br><br> return $block;<br> }<br>}<br>else {<br> return; // you want to make sure this block is not displayed on other pages.<br><div><div></div><div class="Wj3C7c">}<br><br>On Feb 7, 2008 12:24 PM, Tony Yarusso <<a href="mailto:tonyyarusso@gmail.com">tonyyarusso@gmail.com</a>> wrote:<br>
> I'm trying to put together a block that will display additional information<br>> on users' blog pages. The person I'm working with wants some of the more<br>> "traditional" blog stuff, like a user picture, short bio, blogroll, and<br>
> archives links shown in the sidebar. All of the actual information is<br>> supported by other modules, so I just need to be able to access it from<br>> within my theme. Essentially, what I'm going for is to load this block<br>
> whenever the node type is 'blog post', and populate it with the content<br>> matching the author of the node.<br>><br>> I am using a small snippet of code that someone else gave me already for<br>> displaying a title. This is residing in node-blog.tpl.php right now and<br>
> works fine:<br>> <?php $the_user = user_load(array('uid' => $node->uid)); ?><br>> <?php if ($the_user->profile_blog_title != ""): ?><br>> <h2><?php print $the_user->profile_blog_title ?></h2><br>
> <?php else: ?><br>> <h2><?php print $node->name . "'s blog" ?></h2><br>> <?php endif; ?><br>><br>> What I've been using so far in my module's implementation of hook_block<br>
> looks like this, which is just worrying about the picture for now:<br>> case 'view':<br>> $block['subject'] = t('Blog');<br>> $the_user = user_load(array('uid' => $node->uid));<br>
> $user_pic = $the_user->picture;<br>> $block['content'] = $user_pic;<br>> return $block;<br>><br>> However, this does not return anything, and upon further investigation with<br>
> print_r(), it appears to be returning the anonymous user from 'uid', which<br>> of course doesn't have a picture associated with it. Part of what I'm not<br>> sure about is whether I can access the node information ($node->uid) from<br>
> within the block, since it's in the sidebar, not the main content area where<br>> the node is loaded. Please excuse me as I'm very new to PHP and Drupal<br>> development, but looking to learn.<br>><br>
> --<br>> Tony Yarusso<br>> <a href="http://tonyyarusso.com/" target="_blank">http://tonyyarusso.com/</a><br></div></div>> _______________________________________________<br>> themes mailing list<br>> <a href="mailto:themes@drupal.org">themes@drupal.org</a><br>
> <a href="http://lists.drupal.org/mailman/listinfo/themes" target="_blank">http://lists.drupal.org/mailman/listinfo/themes</a><br>><br>><br>_______________________________________________<br>themes mailing list<br>
<a href="mailto:themes@drupal.org">themes@drupal.org</a><br><a href="http://lists.drupal.org/mailman/listinfo/themes" target="_blank">http://lists.drupal.org/mailman/listinfo/themes</a><br></blockquote></div><br>Ah, okay. That worked, but only partially. I now have things displaying okay when looking at any individual blog post (ie, 'blog/tony/2008/01/31/converted-site-drupal'), but not on the main blog pages ('blog', 'blog/tony', etc.). Apparently this is because those are "views", not nodes, but I'm not really sure how to interact with a view now. To make things more complicated, it only makes sense to display this stuff when everything belongs to the same user, so 'blog/tony' should show the block, but not just 'blog'.<br clear="all">
<br>-- <br>Tony Yarusso<br><a href="http://tonyyarusso.com/">http://tonyyarusso.com/</a>