Page 1 of 1

Printf question

Posted: Sat Sep 10, 2011 2:58 pm
by jeanL
I am using a Wordpress theme named The_erudite and I find a lot of PHP statments reading as follow: <?php printf( __( 'Posted in %s', 'erudite' ),get_the_category_list(', ') ) ?> <?php printf( __( 'By %s', 'erudite' ), erdt_get_author_posts_link() ) ?> <?php printf( __( 'Permalink to %s', 'erudite' ), the_title_attribute('echo=0') ) ?>" rel="bookmark"><?php the_title() ?>

Code: Select all

<?php the_excerpt(__( 'Read More <span class="meta-nav">&rarr;</span>', 'erudite' )) ?>[syntax=php]
What is the second parameter 'erudite' for ??? What does it do ??
I understand and use PHP quite a bit but don't understand this one !
Anybody an idea to explain this ?
Thanks for help

Re: Printf question

Posted: Sat Sep 10, 2011 3:57 pm
by flying_circus
jeanL wrote:I am using a Wordpress theme named The_erudite and I find a lot of PHP statments reading as follow: <?php printf( __( 'Posted in %s', 'erudite' ),get_the_category_list(', ') ) ?> <?php printf( __( 'By %s', 'erudite' ), erdt_get_author_posts_link() ) ?> <?php printf( __( 'Permalink to %s', 'erudite' ), the_title_attribute('echo=0') ) ?>" rel="bookmark"><?php the_title() ?>

Code: Select all

<?php the_excerpt(__( 'Read More <span class="meta-nav">&rarr;</span>', 'erudite' )) ?>[syntax=php]
What is the second parameter 'erudite' for ??? What does it do ??
I understand and use PHP quite a bit but don't understand this one !
Anybody an idea to explain this ?
Thanks for help
When in doubt, RTFM :)
http://us3.php.net/manual/en/function.sprintf.php


Basically, printf/sprintf takes any number of arguments. The 1st parameter is a string containing variables (in the format of %<variable tyle>). After the first parameter is set with x number of variables, printf/sprintf expects that many more arguments.

Thus: printf( 'By %s', 'erudite' ) will output a string 'By erudite'.

%s is a variable, or place holder, for string type data.

If you want to use more than 1 variable, you can:
printf('You are %s posts on %s. The creator of this example is %s', 'viewing', 'devnetwork.net', 'flying_circus')
Output: You are viewing posts on devnetwork.net. The creator of this example is flying_circus'.

Re: Printf question

Posted: Sun Sep 11, 2011 12:39 am
by jeanL
Thank you very much ! I understand exactly how to use it, thanks to your examples.
Rgds from France
Jean

Re: Printf question

Posted: Sun Sep 11, 2011 9:03 am
by ok
Well, you are not totally right.

Wordpress as a custom function named "__" (2 underscore chars). This function translate strings by using the PHP's gettext.

The Wordpress function "__" is defined in wp-includes/l10n.php, more on this function can be found here:
http://codex.wordpress.org/Function_Reference/_2

Basically, the first parameter is a string to be localized, and the second string is called the domain, which tells Wordpress from where to get the translation.

Re: Printf question

Posted: Sun Sep 11, 2011 12:35 pm
by flying_circus
ok wrote:Well, you are not totally right.

Wordpress as a custom function named "__" (2 underscore chars). This function translate strings by using the PHP's gettext.

The Wordpress function "__" is defined in wp-includes/l10n.php, more on this function can be found here:
http://codex.wordpress.org/Function_Reference/_2

Basically, the first parameter is a string to be localized, and the second string is called the domain, which tells Wordpress from where to get the translation.
Thanks for pointing that out, I am definately not a word press developer :)