从您对我的第一个答案的评论来看,我认为您希望应用过滤器。
function lpe_get_comments_number( $anchor=\'#comments\' ) {
$return = \'<a class="comments-number-link" href="\' . get_permalink() . $anchor . \'">\';
$args = array(
\'zero\' => \'Zero comments\',
\'one\' => \'One comment\',
\'more\' => \'% Comments\'
);
$filtered_args = apply_filters( \'choose_your_hook_name\', $args );
// be sure all keys in the filtered args are present and have a valid value
// this is optional but usefull
$args = wp_parse_args( $filtered_args, $args );
$return .= get_comments_number( $args[\'zero\'], $args[\'one\'], $args[\'more\'] ); // \'0\', \'1\', \'%\'
$return .= \'</a>\';
return $return;
}
add_filter( \'choose_your_hook_name\', \'your_filter_callback\', 1, 1 );
function your_filter_callback( $args ) {
return array( \'zero\' => \'Foo Comments\', \'one\' => \'Bar Comments\' );
}
您还可以将其他参数传递给
apply_filters()
如果要根据传递的参数来决定事情,请执行以下操作:
$zero = \'Zero Comments\';
if ( $today == \'sunday\' ) {
$foo = \'Sunday, yeah!\';
} else {
$foo = \'\';
$bar = \'No sunday\';
}
$zero = apply_filters( \'choose_your_hook_name\', $zero, $foo, $bar );
get_comments_number( $zero, $one, $more );
[更多代码]
add_filter( \'choose_your_hook_name\', \'your_filter_callback\', 1, 3 );
function your_filter_callback( $zero, $foo = \'\', $bar = \'\' ) {
if ( ! empty( $foo ) )
$zero = \'No comments on sunday!\';
elseif( ! empty( $bar ) )
$zero = $bar . \', here are % comments\';
return $zero;
}