GetSimple Support Forum

Full Version: [Resolved] Display name not Username
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In my template, can I display the Display Name that you can enter in the User Profil ?
If I used the tag : <?php echo $data_index->author; ?>, it's the Username which is displayed.
Is it possible ?
Thank's for your help !
Which template do you use? Which plugins?
The default template (Innovation) and no plugin. Just a test on localhost.
Did you dig through the wiki?
http://get-simple.info/wiki/
and the forum:
http://get-simple.info/forums/showthread.php?tid=3371

I haven't tinkered this far yet but by glancing at:
http://code.google.com/p/get-simple-cms/...tail?r=755

It seems that you can manually get that information by parsing the user data via your functions file and echo it via php onto your template if defined.

So try:

<?php echo $data->NAME; ?>
or
<?php echo $data_index->NAME; ?>
and let us know if it works....
Author in pages is defined as username.

You can retrieve the name from the userfile in /data/users/.

But there will be also other solutions...
@WebDevandPhoto
If I use <?php echo $data->NAME; ?> or <?php echo $data_index->NAME; ?>, nothing is displayed.
With <?php echo $data_index->author; ?>, it's the Username, but not the Display Name.
The wiki page about author : author snippet
What version of GS are you using ?
Name is not stored in pages.
You would have to look it up in the users datafile for that user.

display name is 3.2+

psuedocode

PHP Code:
    if (file_exists(GSUSERSPATH $author '.xml')) {
        
$data getXML(GSUSERSPATH  $author '.xml');
        
$NAME stripslashes($data->NAME);
    } 
I use the last version, v3.2
(2013-02-21, 23:59:13)shawn_a Wrote: [ rel="nofollow" -> ]
PHP Code:
    if (file_exists(GSUSERSPATH $author '.xml')) {
        
$data getXML(GSUSERSPATH  $author '.xml');
        
$NAME stripslashes($data->NAME);
    } 

Did it work for you krysttof?
If this is something you want then write a plugin or use my hook plugin.
And on page save add the display name to extra fields, then it will be in $data_index. Of course it will be static and not update.

on changedata hook
add custom field name->$datau->NAME;
i used this code in my template :
Code:
<?php
   if (file_exists(GSUSERSPATH.$author.'.xml')) {
      $data = getXML(GSUSERSPATH.$author.'.xml');
      $NAME = stripslashes($data->NAME);
   };
?>
And I have this error :
Code:
Notice: Undefined variable: author in /Users/mymac/Sites/gs32/theme/Simple DeepBlue/template.php on line 47
That waspsuedo code, you have to define author or use data index author
shawn_a,
I'm really sorry, I'm a newbie with PHP, so I don't know what to do with your code, with the variables $author, $data_index, $NAME...
Blush
No little help ?
$data_index->author; its in the first post you posted.
Where are you putting this code theme , component function ?
PHP Code:
<?php
   
if (file_exists(GSUSERSPATH.$data_index->author.'.xml')) {
      
$data getXML(GSUSERSPATH.$author.'.xml');
      
$NAME stripslashes($data->NAME);
   }; 
?>
shawn_a, if I put your previous PHP Code (#17) in my template.php file, nothing is displayed !
I guess I have to displayed a variable ?
But wath variable ?
And how ?
cf my post #13
that is just the function you have to echo $NAME somewhere.
In my functions.php, I have this code :
PHP Code:
if (file_exists(GSUSERSPATH.$data_index->author.'.xml')) {
    
$data getXML(GSUSERSPATH.$author.'.xml');
    
$NAME stripslashes($data->NAME);


In my template.php file, I have this code :
PHP Code:
<p>Auteur : <?php echo $NAME?></p> 

Nothing is displayed and I have two errors :
PHP Code:
NoticeUndefined variableauthor in /Users/mymac/Sites/gs-site/theme/mytheme/functions.php on line 51
Notice
Trying to get property of non-object in /Users/mymac/Sites/gs-site/theme/mytheme/functions.php on line 52 

The line 51 : $data = getXML(GSUSERSPATH.$author.'.xml');
The line 52 : $NAME = stripslashes($data->NAME);
sorry

PHP Code:
<?php

   $author 
$data_index->author;
   if (
$author && file_exists(GSUSERSPATH.$author.'.xml')) {
      
$data getXML(GSUSERSPATH.$author.'.xml');
      
$NAME stripslashes($data->NAME);
   }; 
?>
Finally it works! The name is displayed!
It was not easy for me, a big thank you shawn_a !
Smile
No problem , it probably needs to be cleaned up to handle empty display names and stuff, but like i said untested code, maybe we we will have something better in a few versions.
Yes !, it might be interesting in the future to have an "official template tag" to display the name in the template.