How do I get User Attributes?

Permalink
Hi

I'm new to php and I'm creating a blog site with Concrete5

I've largely used the sample data to get up and running, but I'm looking to change the user name on my blog postings. I want to log in as "admin", but I want blog posts to show my Pseudonymn.

I've created an additional attribute in the user database called "display_name", but I don't know how to call it.

This is the section in "blog_entry.php", that needs editing.

<div class="pageSection">
            <h1><?php  echo $c->getCollectionName(); ?></h1>
            <p class="meta"><?php  echo t('Posted by')?> <?php  echo $c->getVersionObject()->getVersionAuthorUserName(); ?> on <?php  echo $c->getCollectionDatePublic('F j, Y'); ?></p>      
         </div>


I know I could just append the name to
t('Posted by')
, but I want to be able to get my head around coding in php.

Any help would be very much appreciated.

 
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Not as straightforward as you're probably hoping, but here's how to do it:
<?php
$uid = $c->getVersionObject()->getVersionAuthorUserID();
$ui = UserInfo::getByID($uid);
$display_name = $ui->getAttribute('display_name');   
?>

Now you can echo $display_name wherever you need in your template. Note that this only retrieves the author associated with the most recent edit to that blog post, not the original author. If you want to get the original author, replace the first line of that code with this:
$uid = Page::getByID($c->getCollectionID(), 1)->getVersionObject()->getVersionAuthorUserID();
justcurious replied on at Permalink Reply
Brilliant. Thanks jordan!

I had to change
$uid = Page::getByID($cobj->getCollectionID(), 1)->getVersionObject()->getVersionAuthorUserID();


to:

$uid = Page::getByID($c->getCollectionID(), 1)->getVersionObject()->getVersionAuthorUserID();


but it works perfectly.

Thanks again!
jordanlev replied on at Permalink Reply
jordanlev
Ahh yes, I mistakenly thought you were talking about the blog_listing page list template, not the blog_entry page type template. Updating my answer to reflect this.
justcurious replied on at Permalink Reply
Hi jordan

Yes, I realised that when I went in to change the blog_listing page list after I'd done the blog_entry page.

It was really helpful, thanks again.