Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
template: Output of the User name - get_page_usr()?
#1
I'm looking for a method to output the user name in a theme file.
For example
Code:
<meta name="author" content="(GS-PAGE-USR-HERE)">
The Template Tags Wiki and the Forum has no function documented for this. Is there one to use?
Advanced HTML5 & CSS3 coder. Simple JS & PHP hacker (not enough for new function coding). Build one webpage with GS (late 2012). Focusing on Theme customizing/Template files. Experience with WP.
Reply
#2
ChriS Wrote:I'm looking for a method to output the user name in a theme file.
For example
Code:
<meta name="author" content="(GS-PAGE-USR-HERE)">
The Template Tags Wiki and the Forum has no function documented for this. Is there one to use?
What exact user do you want to place within template ?

I'd suggest to use a function which would take the <user><![CDATA[user]]></user> from xml file.
You can base on excerpt script I've made long time ago, and use it to grab the user variable.
Addons: blue business theme, Online Visitors, Notepad
Reply
#3
yojoe Wrote:I'd suggest to use a function which would take the <user><![CDATA[user]]></user> from xml file.
You can base on excerpt script I've made long time ago, and use it to grab the user variable.
<user><![CDATA[user]]></user> from xml file is exactly the info I want to extract.
Youn mean this display page excerpt - plugin (Forum) (Plugin page)?
I fear my PHP knowledge is to poor to code a new plugin; I'm only able to hack some obvious things. Undecided Maybe I will try; but I prefer to use the core or a well developed plugin. ;-)

Maybe it is possible to grab the user with one of the blog capable plugins (author of the post)? I have to digg deeper. Thank you for every advise!
Advanced HTML5 & CSS3 coder. Simple JS & PHP hacker (not enough for new function coding). Build one webpage with GS (late 2012). Focusing on Theme customizing/Template files. Experience with WP.
Reply
#4
ChriS Wrote:I'm looking for a method to output the user name in a theme file.
For example
Code:
<meta name="author" content="(GS-PAGE-USR-HERE)">
The Template Tags Wiki and the Forum has no function documented for this. Is there one to use?

There isn't a template tag for user/author right now. Meanwhile you can do it like this (GS 3.1):
Code:
<meta name="author" content="<?php echo $data_index->author; ?>">

Edit: there's another way (also with GS 3.1):
Code:
<meta name="author" content="<?php getPageField(return_page_slug(),'author'); ?>">
Reply
#5
Carlos Wrote:There isn't a template tag for user/author right now. Meanwhile you can do it like this (GS 3.1):
Code:
<meta name="author" content="<?php echo $data_index->author; ?>">

Edit: there's another way (also with GS 3.1):
Code:
<meta name="author" content="<?php getPageField(return_page_slug(),'author'); ?>">
Wow! Very thank you! This is the second time you gave just the right code I was searching for!
Your support is very good. This functions would be useful for the Wiki?
Advanced HTML5 & CSS3 coder. Simple JS & PHP hacker (not enough for new function coding). Build one webpage with GS (late 2012). Focusing on Theme customizing/Template files. Experience with WP.
Reply
#6
ChriS Wrote:I'm only able to hack some obvious things. Undecided Maybe I will try; but I prefer to use the core or a well developed plugin. ;-)

If Carlos solution won't be sufficient, place below code in functions.php file (same directory as template.php) and call it function from template
Code:
function show_author($id){
    $file = "data/pages/". $id .".xml";
    if ( file_exists($file) ){
        $data_index = getXML($file);
        $author = 'stripslashes(html_entity_decode($data_index->user, ENT_QUOTES, 'UTF-8') );
    }else{
        $author="";
    }
    
    return $author;
}


and call it function from template below the function showing page's content (it depends of course on where you want to place author's name)

Code:
<?php echo show_author(return_page_slug()); ?>

Function will show empty string if page does not exist Wink

ps. I didn't test this, but the code should work.
Addons: blue business theme, Online Visitors, Notepad
Reply
#7
yojoe Wrote:If Carlos solution won't be sufficient, place below code in functions.php file (same directory as template.php) and call it function from template ...
Both functions of Carlos work for me, but thank you yojoe! Your solution shows a nice way of customizing the output for a theme and a more secure way of echoing user. I use now the folowing code in the theme file:
Code:
<meta name="author" content="<?php echo stripslashes(html_entity_decode($data_index->user, ENT_QUOTES, 'UTF-8') ); ?>">
Advanced HTML5 & CSS3 coder. Simple JS & PHP hacker (not enough for new function coding). Build one webpage with GS (late 2012). Focusing on Theme customizing/Template files. Experience with WP.
Reply




Users browsing this thread: 1 Guest(s)