Page 1 of 1

[SOLVED] Display name

Posted: Wed Jan 07, 2009 10:35 am
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!

Re: Display name

Posted: Wed Jan 07, 2009 2:22 pm
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)

Re: Display name

Posted: Wed Jan 07, 2009 4:27 pm
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

Re: Display name

Posted: Wed Jan 07, 2009 7:07 pm
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

Re: Display name

Posted: Thu Jan 08, 2009 4:02 pm
by johan_jnsson
Thank you! Now I a got it to work!

Thanks once again.