Show the name of a blog post's author
2 posts by 2 authors in: Forums > CMS Builder
Last Post: July 9, 2015 (RSS)
Please can you tell me how to show the name of the person who authored a blog post? I'd like to do this on both the list and detail page.
I have this in the head of my list template:
// load records from 'blog'
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'perPage' => '5',
'loadCreatedBy' => '',
'loadUploads' => true,
'allowSearch' => false,
));
This is the line where I want to show the author's name:
Posted by ??? on <?php echo date("l, F jS, Y g:i a", strtotime($record['date'])) ?>
This is the live list page: http://gaiasgardens.ca/blog.php
By Daryl - July 9, 2015
Hi,
If the author is stored in "createdBy.fullname", you should set the 'loadCreatedBy' => '', to true or just simply remove it from the load records block.
So to display the author's name, it should be:
Posted by <?php echo htmlencode($records['createdBy.fullname']); ?> on <?php echo date("l, F jS, Y g:i a", strtotime($record['date'])) ?>
If you're not sure which variable does the author's name value is stored, can you try to add showme($blogRecords); after the load records block:
// load records from 'blog'
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'perPage' => '5',
'loadUploads' => true,
'allowSearch' => false,
));
showme($blogRecords);
And find the array that contains the author's name. For example:
array[0] =>
array(
createdDate => "",
// ....... more array keys to values
author => "example",
// ....... more array keys to values
);
In the example above, the "author" array key holds the value of the author name. So on your code, it will be:
Posted by <?php echo htmlencode($records['author']); ?> on <?php echo date("l, F jS, Y g:i a", strtotime($record['date'])) ?>
Hope this helps.
Cheers,
PHP Programmer - interactivetools.com