Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Resolved] Display name not Username
#1
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 !
Français et éternel débutant
French and eternal beginner
Reply
#2
Which template do you use? Which plugins?
Reply
#3
The default template (Innovation) and no plugin. Just a test on localhost.
Français et éternel débutant
French and eternal beginner
Reply
#4
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....
Reply
#5
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...
Reply
#6
@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
Français et éternel débutant
French and eternal beginner
Reply
#7
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);
    } 
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#8
I use the last version, v3.2
Français et éternel débutant
French and eternal beginner
Reply
#9
(2013-02-21, 23:59:13)shawn_a Wrote:
PHP Code:
    if (file_exists(GSUSERSPATH $author '.xml')) {
        
$data getXML(GSUSERSPATH  $author '.xml');
        
$NAME stripslashes($data->NAME);
    } 

Did it work for you krysttof?
Reply
#10
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;
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#11
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
Français et éternel débutant
French and eternal beginner
Reply
#12
That waspsuedo code, you have to define author or use data index author
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#13
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
Français et éternel débutant
French and eternal beginner
Reply
#14
No little help ?
Français et éternel débutant
French and eternal beginner
Reply
#15
$data_index->author; its in the first post you posted.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#16
Where are you putting this code theme , component function ?
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#17
PHP Code:
<?php
   
if (file_exists(GSUSERSPATH.$data_index->author.'.xml')) {
      
$data getXML(GSUSERSPATH.$author.'.xml');
      
$NAME stripslashes($data->NAME);
   }; 
?>
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#18
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
Français et éternel débutant
French and eternal beginner
Reply
#19
that is just the function you have to echo $NAME somewhere.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#20
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);
Français et éternel débutant
French and eternal beginner
Reply
#21
sorry

PHP Code:
<?php

   $author 
$data_index->author;
   if (
$author && file_exists(GSUSERSPATH.$author.'.xml')) {
      
$data getXML(GSUSERSPATH.$author.'.xml');
      
$NAME stripslashes($data->NAME);
   }; 
?>
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#22
Finally it works! The name is displayed!
It was not easy for me, a big thank you shawn_a !
Smile
Français et éternel débutant
French and eternal beginner
Reply
#23
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.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#24
Yes !, it might be interesting in the future to have an "official template tag" to display the name in the template.
Français et éternel débutant
French and eternal beginner
Reply
#25
(2013-04-06, 00:39:17)shawn_a Wrote: sorry

PHP Code:
It still work fine


<?
php

   $author 
$data_index->author;
 
  if ($author && file_exists(GSUSERSPATH.$author.'.xml')) {
 
     $data getXML(GSUSERSPATH.$author.'.xml');
 
     $NAME stripslashes($data->NAME);
 
  }; 
?>
My website made with GetSimple CMS is

Arte & Società
www.artesocieta.eu

An indipendent website about Italian Contemporary Visual Arts
Reply




Users browsing this thread: 1 Guest(s)