正如文章所示,ob_start 和ob_get_clean 可以捕获典型的循环输出并作为变量返回。当您处于循环中时,您可能希望确保\\u内容也呈现其短代码。
function do_livecasinoss_shortcode($atts, $content = "") {
// start the buffer
ob_start();
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'post_type\' => \'casino\',
\'posts_per_page\' => 5,
\'orderby\' => \'date\',
\'paged\' => $paged,
);
$wp_query = new WP_Query($args);
/* PageNavi at Top */
if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post();
/* DO STUFF IN THE LOOP */
// run any shortcode items inside the_content
echo apply_filters(\'the_content\', get_the_content());
?>/* Post Loop */<?php
endwhile; endif;
wp_reset_query();
// stop the buffer / capture and return the output
return obj_get_clean();
}
add_shortcode(\'livecasinoss\', \'do_livecasinoss_shortcode\');
// Wrapper for livecasinoss shortcode
function do_livecasinos_shortcode($atts, $content = "") {
// return rendered shortcode
return do_shortcode(\'[livecasinoss]\');
}
add_shortcode(\'livecasinos\', \'do_livecasinos_shortcode\');