我正在尝试让wordpress的gravatar在sprintf语句中工作。
<?php
if ( 'on' === $show_author || 'on' === $show_date || 'on' === $show_categories || 'on' === $show_comments ) {
printf( '<div class="post-wrapper"><p class="post-meta">%1$s %2$s %3$s %4$s %5$s <span class="comments">%6$s</span></p></div>',
(
'on' === $show_author
? et_get_safe_localization( sprintf( __( 'By: %s', 'et_builder' ), '<span class="vcard2">' . get_avatar( get_the_author_meta('ID'), 80) . '</span><span class="author">' . et_pb_get_the_author_posts_link() . '</span>' ) )
: ''
),
(
( 'on' === $show_author && 'on' === $show_date )
? ' '
: ''
),
(
'on' === $show_date
? et_get_safe_localization( sprintf( __( '%s', 'et_builder' ), '<span class="published">' . esc_html( get_the_date( $meta_date ) ) . '</span>' ) )
: ''
),
(
(( 'on' === $show_author || 'on' === $show_date ) && 'on' === $show_categories)
? ' '
: ''
),
(
(( 'on' === $show_author || 'on' === $show_date || 'on' === $show_categories ) && 'on' === $show_comments)
? ' | '
: ' '
),
(
'on' === $show_comments
? sprintf( esc_html( _nx( '1 Comment', '%s Comments', get_comments_number(), 'number of comments', 'et_builder' ) ), number_format_i18n( get_comments_number() ) )
: ''
)
);
}
?>问题出在sprintf函数上。
? et_get_safe_localization( sprintf( __( 'By: %s', 'et_builder' ), '<span class="vcard2">' . get_avatar( get_the_author_meta('ID'), 80) . '</span><span class="author">' . et_pb_get_the_author_posts_link() . '</span>' ) )如果我把echo放在前面,语法错误。如果我用分号结束它,语法错误。
它似乎根本不承认get_avatar( get_the_author_meta('ID'), 80),它只是被忽略了。不会向html输出任何内容。
在WordPress讨论选项中选中显示头像。
将输出以下内容的测试页面:Test page
发布于 2016-07-22 04:02:08
在经历了几个小时的挫折之后,我终于找到了答案。
<?php
if ( 'on' === $show_author || 'on' === $show_date || 'on' === $show_categories || 'on' === $show_comments ) {
echo get_avatar( $post->post_author, 80 );
printf( '<div class="post-wrapper"><p class="post-meta">%1$s %2$s %3$s %4$s %5$s <span class="comments">%6$s</span></p></div>',
(
'on' === $show_author
? et_get_safe_localization( sprintf( __( 'By: %s', 'et_builder' ), '<span class="vcard2">' . get_avatar( $post->post_author, 80 ) . '</span><span class="author">' . et_pb_get_the_author_posts_link() . '</span>' ) )
: ' '
),
(
( 'on' === $show_author && 'on' === $show_date )
? ' '
: ''
),
(
'on' === $show_date
? et_get_safe_localization( sprintf( __( '%s', 'et_builder' ), '<span class="published">' . esc_html( get_the_date( $meta_date ) ) . '</span>' ) )
: ''
),
(
(( 'on' === $show_author || 'on' === $show_date ) && 'on' === $show_categories)
? ' '
: ''
),
(
(( 'on' === $show_author || 'on' === $show_date || 'on' === $show_categories ) && 'on' === $show_comments)
? ' | '
: ' '
),
(
'on' === $show_comments
? sprintf( esc_html( _nx( '1 Comment', '%s Comments', get_comments_number(), 'number of comments', 'et_builder' ) ), number_format_i18n( get_comments_number() ) )
: ''
)
);
}
?>我必须在sprintf语句之前包含echo,并通过css处理它。
https://stackoverflow.com/questions/38466480
复制相似问题