Fatal Error on blog_entry.php

Permalink
I wanted my blog pages to display the blog author's name so I created a text attribute called "author". I then changed in blog_entry.php

By <?php echo $userName; ?>

to

By <?php $c = Page::getCurrentPage();
$uID = $c->getCollectionUserID();
$ui = UserInfo::getByID($uID);
print $ui->getAttribute('author'); ?>

and it works fine. You can see it in action here:
http://www.knowleskreative.com/blog/dont-hire-web-designer-you-need...

However, when I go to Dashboard -> Pages & Themes -> Page Types
and click on Defaults for blog_entry I get the following error:

Fatal error: Call to a member function getAttribute() on a non-object in /home5/keithkno/public_html/knowleskreative/themes/default/blog_entry.php on line 40

If I revert the lines of code above the error goes away but so does my author's name from the blog article.

Can this be fixed?
Thanks.

kreative
 
Mnkras replied on at Permalink Best Answer Reply
Mnkras
<?php
$c = Page::getCurrentPage();
if(is_object($c)) {
    $uID = $c->getCollectionUserID();
    $ui = UserInfo::getByID($uID);
    if(is_object($ui)) {
        print $ui->getAttribute('author');
    } else {
        print t('Unknown User');
    }
}
?>


Try that out.
kreative replied on at Permalink Reply
kreative
Perfect. Thanks!