We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

plugin to display avatar or default avatar in forums

Development and Programming

DougH's avatar
DougH
205 posts
15 years ago
DougH's avatar DougH

I want to display a default avatar in the forums (v2.1.2) if a user doesn’t have one.

Since {if:else} doesn’t work with {if avatar} in forum templates, I thought a plugin would be the way to go.

Here’s what I have so far:

<?php

class Display_avatar
{

var $return_data = "";

  function Display_avatar()
  {
    global $TMPL, $DB;

    $author_name = $TMPL->tagdata;

    $query = $DB->query("SELECT screen_name, avatar_width
      FROM exp_members WHERE screen_name='$author_name'");

foreach($query->result as $row)
    {

if ( $row['avatar_width'] == "0" ) {
    echo "NO AVATAR!";
      }      

if ( $row['avatar_width'] != "0" ) {
    echo "AVATAR";
      }

    }


  }

}

?>

I have “NO AVATAR!” and “AVATAR” in there for right now just to check and make sure the conditional will work.

To pass the name of each poster in the “Thread Rows” forum template to the plugin, I have

{exp:display_avatar}{author}{/exp:display_avatar}

where the {if avatar} conditional was.

Now here’s something strange that’s happening.

Instead of putting “NO AVATAR!” or “AVATAR” where the avatar should be, it’s writing a continuous string up at the very top of the screen like this:

“NO AVATAR!AVATARAVATARAVATARNO AVATAR!NO AVATAR!AVATAR”

What is echoed is correct so the conditional is working properly. But why is it doing this?

       
DougH's avatar
DougH
205 posts
15 years ago
DougH's avatar DougH

I narrowed it down to the “echo”.

When I switched “echo” to “$this->return_data =” it worked like a champ.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.