use*_*968 8 wordpress shortcode
我知道这可能是一个回归问题.所以我把内容分开了,一个在一个函数中调用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;
}
Run Code Online (Sandbox Code Playgroud)
小智 25
你希望返回所有的文本,而不是当你逃避PHP时输出它.
在thelist()函数的开头,启动一个输出缓冲区
ob_start();
Run Code Online (Sandbox Code Playgroud)
然后在最后关闭此缓冲区并返回其内容
return ob_get_clean();
Run Code Online (Sandbox Code Playgroud)
这将返回内容而不是直接回复它,这是你想要在WP短代码中做的事情
| 归档时间: |
|
| 查看次数: |
3576 次 |
| 最近记录: |