我正在尝试从自定义查询添加帖子列表
while ( $the_query->have_posts()) : $the_query->the_post();
进入do_shortcode
. 我该怎么做?
我正在尝试从自定义查询添加帖子列表
while ( $the_query->have_posts()) : $the_query->the_post();
进入do_shortcode
. 我该怎么做?
我希望我能正确地理解你的意思,所以我会相应地回答你。要使其工作,您需要在短代码中添加完整的自定义查询。看看Shortcode API 短代码如何工作以及如何使用。
但是要记住的一点是,短代码的输出不应该是echo
ed,但是returned
我想你用过WP_Query
构造自定义查询
您可以根据此示例创建您的短代码
add_shortcode( \'my-shortcode\', \'my_custom_query_shortcode\' );
function my_custom_query_shortcode( $atts ) {
ob_start();
$the_query = new WP_Query( \'YOUR ARGUMENTS TO USE\' );
if ( $the_query->have_posts() ) :
while($the_query->have_posts()) : $the_query->the_post();
<---YOUR LOOP ELEMENTS HERE--->
endwhile;
$myvariable = ob_get_clean();
return $myvariable;
endif;
}
这就是您的短代码在中的使用方式do_shortcode
echo do_shortcode(\'[my-shortcode]\');
我甚至不知道这是否可能array_map 或str_replace, 但想法如下:此函数用于获取发送前的内容,clean_custom_content, 这就是我不知道如何处理的地方。。所以让我们假设我们拥有所有的内容,这些内容将被包装在section 但每次都有一个简短的代码[] 这需要在输出短代码的内容时关闭。他们打开了一个新的section 并继续该页面的内容。有意义吗?任何想法或帮助都会很好。。谢谢function get_custom_content( $more_link_text = nul