Membership plugin - author specific photo
16 posts by 4 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: January 31, 2012 (RSS)
By Gabums85 - January 30, 2012
For this code:
<?php foreach ($accountsRecords as $record) :?>
<?php showme($record); ?>
<?php die(); ?>
<?php foreach ($record['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php endforeach ?>
i got this:
[createdBy.avatar] => Array ( )
for this code:
<?php foreach ($blog_avatarsRecords as $record) :?>
<?php showme($record); ?>
<?php die(); ?>
<?php foreach ($record['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php endforeach ?>
i got a huge string of information. But most notably it linked to my image (yay). So I changed the code to read as follows:
<?php foreach ($blog_avatarsRecord['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php if (!$blog_avatarsRecord['createdBy.avatar']): ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif ?>
but it shows up for EVERY posting. Not solely the one that I created. I wanted the "fpo" image to populate if the user has not uploaded their own image yet...
I can't tell you all how much I appreciate you everyone hanging in there with me for this and trying to help out. I feel like we are getting close(ish) and just wanted to cheer you on a bit longer :)
Thank you so much!
Re: [Gabums85] Membership plugin - author specific photo
By (Deleted User) - January 30, 2012
You're very close withg your code. Try this instead:
<?php foreach ($blog_avatarsRecord['createdBy.avatar'] as $upload): ?>
<?php if ( @$upload ) : ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php else : ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif; ?>
<?php endforeach ?>
Basically, you want to check for the existence of the avatr while in the for loop, as the output of the img url happens in the loop.
Hope that helps,
Tom
Re: [Gabums85] Membership plugin - author specific photo
By gkornbluth - January 30, 2012 - edited: January 30, 2012
In the code that you're using, shouldn't the logic be something like:
<?php foreach ($blog_avatarsRecords as $record) :?>
<?php if ($record['createdBy.avatar']): ?>
<?php foreach ($record['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php else : ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif ?>
<?php endforeach ?>
Also, instead of urlPath, why not use thumbUrlPath and set the thumbnail sizes to 75 x 75 in the editor?
Using:
<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo
$upload['thumbHeight'] ?>
you'll get to display a small thumbnail image to begin with and not get distorted images if the aspect ratio of the original is not exactly square.Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Membership plugin - author specific photo
By Gabums85 - January 31, 2012
Ok I got it working kinda but there is some funky stuff going on. I'm going to attach a stripped down file to see if maybe that will help. So when I did the error testing again that Tom recommended, I noticed that the uploaded images from the Blog_Avatars table won't work unless there is an avatar upload form in the Accounts table as well... So now I have them both up and both with images downloaded to the tables. Anyways, using this code:
<?php if ($record['createdBy.avatar']): ?>
<?php foreach ($blog_avatarsRecord['avatar'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" />
<?php endforeach ?>
<?php else : ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif ?>
Causes the last image that has been added to the manager to be the one that shows up when there is an image created by the user. So my boss uploaded her image after I had, and now for my posts, her image comes up as well as on her own posts. The else statement works. This is the closest I have gotten with every variation of the code I can think of...
Thanks again everyone! You're lifesavers :)
Re: [Gabums85] Membership plugin - author specific photo
By Jason - January 31, 2012
You're really close. If the avatar is supposed to be an image associated with the person who created the record, you won't need this extra avatar table. In your code you are limiting the query to only retrieve a single record from the blog_avatars table, which is why it is repeating. You need the code to output the createdBy.avatar field, as this will be the image uploaded to the avatar field of the accounts table for the user that created the record.
try this:
<?php if ($record['createdBy.avatar']): ?>
<?php foreach ($record['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" />
<?php endforeach ?>
<?php else : ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif ?>
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Membership plugin - author specific photo
By Gabums85 - January 31, 2012 - edited: January 31, 2012
::EDIT::
So as much as I would love to take credit for this being solved... my boss is the one who figured out the code :)
Here it is if anyone wants to know:
<?php $post_author = $record['createdBy.username'] ?>
<!-- SET VARIABLE TO DETERMINE IF USER UPLOADED AN IMAGE -->
<?php $avatar_match = 0; ?>
<!-- LOAD AVATAR -->
<?php foreach ($blog_avatarsRecords as $record): ?>
<?php if ($record['name'] == $post_author): ?>
<?php foreach ($record['avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php $avatar_match +=1; ?>
<?php endif ?>
<?php endforeach ?>
<!-- IF NO RECORDS MATCH, LOAD GENERIC IMAGE -->
<?php if ($avatar_match == 0): ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif ?>
Thank you very much to everyone who has been helping me through this the last few days. Hopefully the above code helps others too.
Gab