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?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.