- b2evolution CMS User Manual
- Developer Reference
- How to... (Customize)
- How to Show the Assigned Author of a post
How to Show the Assigned Author of a post
Posts are by default assigned to the creator - the author who is logged in when they are created. Sometimes you may wish to change this either at editing time or subsequently. This hack can be used to change the displayed author of a post by just changing the assigned author in the post editing form.
Show the assigned author of the article and other details
If no author is assigned, display the creator of the article.
Show the Prefered Name (Identity Shown) with a link to all the articles of that person
<?php
$Item->get_creator_User();
if( $Item->assigned_user_ID )
{
$the_author = $UserCache->get_by_ID( $Item->assigned_user_ID );
}
else
{
$the_author = $Item->Author;
}
echo '<a href="'.url_add_param( $Blog->get( 'blogurl', 'htmlattr' ), 'author='.$the_author->ID).'" title="Browse all articles from '.$the_author->get_preferred_name().'"><img src="rsc/icon_16_author.gif" border="0"></a>';
?>
And once you did that, you want the messageform-link to go to the right user, right ?
$the_author->msgform_link( $Blog->get('msgformurl'),' ',' ','#','Send an e-mail to '.$the_author->get_preferred_name(),'' );
Show simply the assigned author name
If you just want to show the assigned author name (not any lists of links or message form) this code will do it:
<?php
$Item->get_creator_User();
if( $Item->assigned_user_ID )
{
$the_author = $UserCache->get_by_ID( $Item->assigned_user_ID );
}
else
{
$the_author = $Item->Author;
}
echo $the_author->get_preferred_name();
?>
You should insert this code into your active _main.php file (the one in whichever template you are using) in the section called ‘—START OF POSTS—’. It should ‘’replace'’ the lines that read something like:
$Item->author( '<strong>', '</strong>' );
$Item->msgform_link( $Blog->get('msgformurl') );
- You will need to remove the surrounding <?php … ?> tags if you are inserting it into an existing php statement.