Theme (PHP Template): Display author userpic from Page template

Events happening in the community are now at Drupal community events on www.drupal.org.
ae@uberellis.com's picture

I need help with the logic to:

  1. Detect whether page.tpl.php is displaying a full node (one only, not listed)
  2. Detect if the author has uploaded a userpic, and if yes, display the userpic. If no, display the default userpic

Is it prudent to rather place this logic into template.php? Code a module? It would be awesome to have access to other features for the userpic, like having the option to either use gravatar url as opposed to uploading a picture. Not to mention anything imagecache as well as allowing the user to crop a square image from the uploaded picture.

As far as I can tell, the $picture variable is only available for node*.tpl.php and comment.tpl.php

Comments

UserPic

SiteMaster.ServeLime.com's picture

Have a look at the Avatar modules: (search downloads: "avatar")

I think it does what you need.

Avatar Approval
Avatar Selection <=
Unique Avatar
Avatar gallery
Avatar Blocks

Good Luck

ServeLime
www.ServeLime.com
Entrepreneurship is a journey to a fulfilled life - make it so.

Emile Botha
Entrepreneurship is a journey to a fulfilled life - make it so.

While we're at it

ae@uberellis.com's picture

Also include posted by information from page.tpl.php

I need these in page.tpl specifically, to modify the page title (area). So.. if I could somehow not show the title in page.tpl, I could add all of the above logic into the node.tpl's

ae@uberellis.com's picture

It's not the most elegant, I know... ImageCache for userpics puh-leeeeze!

      <?php if ($submitted): ?>
        <?php if ($node->picture != '') { ?>
            <div class="picture"><img src="/<?php print $node->picture ?>" width="35px" height="35px" /></div><!-- $picture returns true -->
      <?php } else { ?>
            <div class="picture"><img src="/<?php print $directory ?>/images/user_default.png" alt="No picture uploaded" width="35px" height="35px" /></div>
     <?php } ?>
       <span class="submitted small"><?php print $submitted ?></span>
     <?php endif; ?>
 
       <?php if ($page == 0): ?>
        <h3><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h3>
      <?php endif; ?>

Maybe (in the

Nightwatch-gdo's picture

Maybe (in the node.tpl.php):

<?php
if ($node->nid == arg(1)) {
?>

and:

<?php
print ($node->picture ? $node->picture : 'No picture');
?>

And/or, to change the page title:

<?php
drupal_set_title
('');
?>
ae@uberellis.com's picture

I get acceptable results when doing the following in page.tpl

<?php if (theme_get_setting('toggle_node_info_'. $node->type)) { ?><div class="picture"><?php if ($node->picture) { print theme('image', $node->picture); } ?></div><?php } ?>

Using the arg(1) (or 0 = 'node') was definitely a step in the right direction! It's downfall is always printing the author user pic regardless of theme settings.

Now to display 'Submitted by' info *koff*

<?php print theme('node_submitted', $node); ?>

You should not rely on the

xano's picture

You should not rely on the path when working in node.tpl.php, but rather on $page, a variable passen on to node.tpl.php that evaluates to TRUE if the node is being viewed as a page and FALSE if the node is being viewed in a list. If you rely on arg(0)/arg(1) node 33 listed in a view at the URL /node/33 would also show the avatar.

South Africa

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: