todd_temple — 2013-04-16T08:50:11-04:00 — #1
I have this snippet of code below:
<h1 class="page-title"><?php printf( __( 'Category Archives: %s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h1>
that returns something like this; "Category Archives: Recent News".
I am wanting to rearrange the output to read something like this; "Recent News Category Archives".
Can someone show me how to do this?
davemaxwell — 2013-04-16T09:18:15-04:00 — #2
Shouldn't it be something as simple as this?
<h1 class="page-title"><?php printf( __( '%s Category Archives', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h1>
todd_temple — 2013-04-16T09:31:02-04:00 — #3
Thanks DaveMaxwell. That worked. I am a PHP noob so it may have been simple for you but I had no idea what I was doing. Thanks again!
davemaxwell — 2013-04-16T09:44:37-04:00 — #4
No worries. To explain for future use - the %s is what is replaced in the statement, so I just moved it from one place in the statement to the other so you got the format you wanted.
todd_temple — 2013-04-16T10:35:58-04:00 — #5
So the percent symbol is the variable that represents the name of the category, correct?
cpradio — 2013-04-16T10:41:28-04:00 — #6
Kind of, the %s is a placeholder for a variable; in this case '<span>' . single_cat_title( '', false ) . '</span>' gets placed where the %s is located.
With printf, you can set placeholders that are replaced when outputted in the order that you list them. Example:
printf('My test with two placeholders %s and %s', 'this shows up after placeholders', 'this shows up after and');
There are a lot more placeholders than just %s that can be used with printf, but you won't run into those often in WordPress.