{This question is marked as duplicate but i think my question and answer to it is much simpler then the original one}
您好,我有以下代码显示在小部件标题之前。因为我从研究中了解到,我必须使用return,但它不起作用。请帮忙。
<?php
function get_review_code(){
echo \'<div class="review-slider-wrap">\';
echo \'<ul class="review-slider">\';
global $post;
$args = array( \'numberposts\' => 10, \'category_name\' => \'review\' );
$posts = get_posts( $args );
foreach( $posts as $post ): setup_postdata($post);
echo \'<li>\';
echo \'<div class="white-curve">\';
echo the_excerpt();
$author_id=$post->post_author;
echo \'<div class="author_full_name">\';
echo \'- \';
echo the_author_meta(\'first_name\'); echo \' \';
echo the_author_meta(\'last_name\');
echo \'</div>\';
echo \'</div>\';
echo get_avatar( $post->post_author, 230 );
echo \'</li>\';
endforeach;
echo \'</ul>\';
echo \'</div>\';
}
add_shortcode(\'review_review\', \'get_review_code\');
SO网友:Jorge Y. C. Rodriguez
快捷方式应返回一个值,如果您回显该值,则会将其置于其他值之前。试试这个:(未测试)
<?php
function get_review_code(){
global $post;
$content = "";
$content .= \'<div class="review-slider-wrap">\';
$content .= \'<ul class="review-slider">\';
$args = array( \'numberposts\' => 10, \'category_name\' => \'review\' );
$posts = get_posts( $args );
foreach( $posts as $post ): setup_postdata($post);
$content .= \'<li>\';
$content .= \'<div class="white-curve">\';
$content .= get_the_excerpt();
$author_id = $post->post_author;
$content .= \'<div class="author_full_name">\';
$content .= \'- \';
$content .= get_the_author_meta(\'first_name\');
$content .= \' \';
$content .= get_the_author_meta(\'last_name\');
$content .= \'</div>\';
$content .= \'</div>\';
$content .= get_avatar( $post->post_author, 230 );
$content .= \'</li>\';
endforeach;
$content .= \'</ul>\';
$content .= \'</div>\';
return $content;
}
add_shortcode(\'review_review\', \'get_review_code\');
?>