冲刺
类似于 打印 但是用于返回结果作为a的值 变量 供以后使用而不是立即输出。
这里’您可以在子主题功能文件中测试的区别。
冲刺
add_action('loop_start','sprintf_example' );
function 冲刺_example() {
$output = 冲刺('%s World', 'Hello' );
echo $output;
}
打印
add_action('loop_start','printf_test' );
function 打印_test() {
printf('%s World', 'Hello' );
}
Both code snippets produce exactly the same result. The only difference is 冲刺
returns the value for the 变量 and 打印
outputs directly.
You can also write the code using 冲刺
like this:
add_action('loop_start','sprintf_example1' );
function 冲刺_example1() {
$text = "Hello";
$output = 冲刺('%s World', $text );
echo $output;
}
和这个:
add_action('genesis_after_header','sprintf_example2' );
function 冲刺_example2() {
$link = get_permalink();
$text = "Hello";
$output = 冲刺('%s World', $text );
printf( '<a href="%s">' . $output . '</a>', $link );
}
或这个:
add_action('wp_head','sprintf_example3' );
function 冲刺_example3() {
$link = get_permalink();
$text = "sprintf";
$output = 冲刺('%s Example', $text );
printf( '<a href="%s">%s</a>', $link, $output );
}
发表评论
你一定是 登录 发表评论。