Community Documentation

Display User Picture on some pages according to content type

Last updated March 19, 2009. Created by joachim on January 1, 2007.
Edited by -Shaman-, iandickson. Log in to edit this page.

Altering the node.tpl file can be used to control where user pictures appear (provided that you have turned them on in User Settings and Theme of course).

For example I had a site which comprised formal pages where avatars were NOT wanted, and a Forum where they were.

In English this means "if the user has a Picture AND the page content TYPE is a FORUM POST - print the picture" (and if it's any other part of the site, then don't print the picture...).

   
<?php if ($picture && $type == 'forum') {
      print
$picture;
    }
?>

Comments

worked a bit different

As I tried the code from above I received a Parse Error.

What worked for me:
(Displays the picture everywhere but in events.)

<?php
if ($picture && $type != 'event'):
?>

<?php
print $picture
?>

<?php
endif;
?>

Can I use OR here to give

Can I use OR here to give more options in displaying the picture? For instance, in my case, I want to OR your given statement since I want to display user pictures in FORUM and SOLUTION content types but no pictures for the rest of the content types.

Jess

Worked for me

Worked great -- make sure you enable "User picture in posts" on your theme, or else there's no function.

"What the world needs is more geniuses with humility; there are so few of us left." - Oscar Levant

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x, Drupal 6.x
Audience
Themers

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.