我知道这可能是退货问题。因此,我将内容进行了划分,一个在名为thelist
的函数中,另一个是将其返回的实际函数。该代码遵循该问题。
实际的短代码有效,但内容显示在其余内容的顶部。我以为now_include_post
返回可以解决它,但是不能解决。有人可以帮忙吗?
function thelist() {
if (have_posts()) : while (have_posts()) : the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class('thumb'); ?>>
<a href="<?php the_permalink() ?>" class="thumb-link">
<?php
if (!post_password_required()) {
if (has_post_thumbnail()) {
the_post_thumbnail();
}
} else {
?>
<img src="<?php bloginfo('template_url') ?>/img/locked.png" />
<?php } ?>
</a>
<h2>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
</div>
<?php /* end post */ ?>
<?php
endwhile;
endif;
wp_reset_query();
}
?>
<?php
function now_include_post($atts) {
$thepostid = intval($atts[id]);
query_posts("p=$thepostid");
$output .= thelist();
return $output;
}
最佳答案
当您转义PHP时,您想返回所有文本而不是在那儿输出。
在thelist()函数的开头,使用以下命令启动输出缓冲区
ob_start();
然后最后关闭此缓冲区,并使用以下命令返回其内容
return ob_get_clean();
这将返回内容,而不是立即回显它,这是在WP短代码情况下要执行的操作
PHP information on Output Buffering Functions