[SOLVED] Display name

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
johan_jnsson
New Member
New Member
Posts: 5
Joined: Wed Jan 07, 2009 9:50 am

[SOLVED] Display name

Post by johan_jnsson »

Hello!

Is there any way to display the owner´s name on every page, the pageowner? I can get the username but not the first and last name...

Help please!
Last edited by johan_jnsson on Thu Jan 08, 2009 4:03 pm, edited 1 time in total.
JayDee
Forum Members
Forum Members
Posts: 13
Joined: Tue Oct 09, 2007 4:21 pm

Re: Display name

Post by JayDee »

Maybe add a little user defined tag?

in template:

Code: Select all

Page owned by {page_owner username=$username}
udt: page_owner

Code: Select all

global $gCms, $db;
$sql = "SELECT first_name, last_name FROM cms_users WHERE username = ?";
$result = $db->Execute($sql, $params['username']);
$names = $result->FetchRow();
echo $names['first-name']. " " . $names['last_name'];
Something like that should work (written this by heart)
nhaack

Re: Display name

Post by nhaack »

Hi Johan,

you could also use the content_dump plug-in for this. It is actually intended to gather information from other pages, but also works great to get owner information of the page that contains the tag.

Place it like this in your template:

Code: Select all


{content_dump this_only=$content_id users=true}

You can then access (amongst others) these data fields:

Code: Select all


$dump [ n ] -> created -> date
$dump [ n ] -> created -> by -> username
$dump [ n ] -> created -> by -> last_name 
$dump [ n ] -> created -> by -> first_name 
$dump [ n ] -> created -> by -> email 

$dump [ n ] -> modified -> date 
$dump [ n ] -> modified -> by -> username 
$dump [ n ] -> modified -> by -> last_name 
$dump [ n ] -> modified -> by -> first_name 
$dump [ n ] -> modified -> by -> email 

You can then use these smarty data elements to do whatever you want with the data. At the end, you could do something like this in your template:

Code: Select all


{content_dump this_only=$content_id users=true}
<p>
   This article was originally written by {$dump[0]->created->by->first_name} {$dump[0]->created->by->last_name}.
   {if $dump[0]->modified->date !=$dump[0]->created->date}
      This article has been modified by  {$dump[0]->modified->by->first_name} {$dump[0]->modified->by->last_name}.
   {/if}
</p>

You can find more information about the plug-in here: http://wiki.cmsmadesimple.org/index.php ... ntent_dump

You can download the plug-in here: http://dev.cmsmadesimple.org/projects/contentdump

Make sure to place the tag into the template and not the content-data ;)

Best
Nils
zigge
Forum Members
Forum Members
Posts: 75
Joined: Tue Jan 22, 2008 6:53 pm

Re: Display name

Post by zigge »

Or create a small, dynamic, simple UDT to be put in your template.

Code: Select all

global $gCms;
$db = &$gCms->GetDb();
$sql = "SELECT first_name, last_name FROM cms_users WHERE user_id=(SELECT owner_id FROM cms_content where content_id="."'".$gCms->variables['content_id']."'".")";
$result = $db->Execute($sql);
$names = $result->FetchRow();
echo $names['first_name']. " " . $names['last_name'];
This will spit out the page owner for each page you display. Just put the {your UDT name} in the template. Add div's, tags and what not to get this as you would like it.

Mats
Last edited by zigge on Wed Jan 07, 2009 7:09 pm, edited 1 time in total.
johan_jnsson
New Member
New Member
Posts: 5
Joined: Wed Jan 07, 2009 9:50 am

Re: Display name

Post by johan_jnsson »

Thank you! Now I a got it to work!

Thanks once again.
Post Reply

Return to “Modules/Add-Ons”