include author in blog list block

Permalink Browser Info Environment
I am trying to include the blog page's author as part of the information available in the Pro Blog Page List.
I've tried to shadow the method used in the actual blog page but that code yields nothing (which is better than an error).
The closest I can get is to return the Author's Unique user number (like the superuser is 1 and the second registered user is 2) using this line of code
<?php
$ak_a = CollectionAttributeKey::getByHandle('blog_author'); 
$authorID = $cobj->getCollectionAttributeValue($ak_a); 
echo $authorID 
?>

What we're trying to accomplish can temporarily be seen here:
http://citizen.mcgstrategic.com:8081/index.php/...
I will also need to find a way to link to the author's member page.

Thanks is advance
Ryan Vars

Type: Discussion
Status: New
cannonf700
View Replies: View Best Answer
RadiantWeb replied on at Permalink Best Answer Reply
RadiantWeb
you're half way there.

next you need to grab the userInfo object and then pull the name like so:

$ui = UserInfo::getByID($authorID);
$name = $ui->getUserFirstName().' '.$ui->getUserLastName();


where the attribute containing the name is called using the user info magic function __call(). so, "$ui->getUser" plus a camel cased name for your user attribute. so if you have a full name attribute instead of first and last with "full_name" for the handle. It would be called in like so: $ui->getUserFullName();

ChadStrat
cannonf700 replied on at Permalink Reply
cannonf700
Brilliant! worked like a charm.
Any thoughts on linking to that author's profile page?
I was using this:
<a href="<?php echo $this->url('/profile','view', $c->getVersionObject()->getVersionAuthorUserID())?>"><?php  echo $c->getVersionObject()->getVersionAuthorUserName(); ?></a>


but this is obviously not going to work. I can make the changes to call the right user name but how do I call that user's profile?

Thanks again.
12345j replied on at Permalink Reply
12345j
profile/view/$authorID should be the link
cannonf700 replied on at Permalink Reply
cannonf700
12345J,
This seems to want to take you to the profile page of the logged in user. What I mean is that if I'm logged in as admin it takes me to the admin profile page. but if i'm logged in as another user(blogger) the same link takes me blogger's profile page.

could you expand the code a little so I make sure I have the context right?

Thanks
12345j replied on at Permalink Reply
12345j
<a href="<?php echo $this->url('/index.php/profile/view/$authorID/)?>"><?php  echo $c->getVersionObject()->getVersionAuthorUserName(); ?></a>
where $authorID is the user id of the poster. You need to have public profiles enabled.
cannonf700 replied on at Permalink Reply
cannonf700
12345J,
Thanks for the response but your code is no-go. It does exactly what I said above - it only takes you to the profile page of the user you are signed in as.
Thanks though.
12345j replied on at Permalink Reply
12345j
really- can you give me the url for the profile of a person that you are not signed in as?
cannonf700 replied on at Permalink Reply
cannonf700
this is what worked:
<a href="<?php echo $this->url('/profile','view', $ui->getUserID())?>">
10010110 replied on at Permalink Reply
10010110
Has anything changed there in version 5.4.2? Because all I’m getting is:
Fatal error: Call to a member function getUserFirstName() on a non-object in [root path]/blocks/problog_list/view.php on line 36


What I have is:
if (count($cArray) > 0) { ?>
<div class="ccm-page-list">
<?php   
  for ($i = 0; $i < count($cArray); $i++ ) {
  …
  …
  $ak_a = CollectionAttributeKey::getByHandle('blog_author'); 
  $authorID = $cobj->getCollectionAttributeValue($ak_a); 
  $ui = UserInfo::getByID($authorID);
  $name = $ui->getUserFirstName().' '.$ui->getUserLastName();


I have also assigned proper values to the default first and last name attributes for the user. Also, I’ve tried the full_name attribute variant but to no avail. Interestingly the first and last name attribute values aren’t displayed on the user detail page in the admin area. Is this a bug?

On another note, I’d like to display the blog title itself on the blog post listing page. How am I gonna do that?
cannonf700 replied on at Permalink Reply
cannonf700
here's what I used and it worked great! but this is before 5.4.2 and before the newest release of ProBlog
<?php  
$ak_a = CollectionAttributeKey::getByHandle('blog_author'); 
$authorID = $cobj->getCollectionAttributeValue($ak_a); 
$ui = UserInfo::getByID($authorID);
$name = $ui->getUserFirstName().' '.$ui->getUserLastName(); echo $name ?>


This grabbed the first and last name of the blog author as identified via the dashboard.
We also used this to link to that author's profile page:
<a href="<?php echo $this->url('/profile','view', $ui->getUserID())?>">
<?php echo $firstName = $ui->getUserFirstName();?> <?php echo $lastName = $ui->getUserLastName();?></a>


Hope that helps!
10010110 replied on at Permalink Reply
10010110
OK, so I’ve found out that the error comes up when a blog post author (or its name(s)) has not been defined. I think I solved it by adding a conditional check:
$ak_a = CollectionAttributeKey::getByHandle('blog_author'); 
$authorID = $cobj->getCollectionAttributeValue($ak_a); 
$ui = UserInfo::getByID($authorID);
if(isset($ui)) {
   $name = $ui->getUserFirstName().' '.$ui->getUserLastName();
}

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.