如何将简码参数$ a变量传递给主题文件
function ctest_shortcode($atts) {
extract(shortcode_atts(array(
'a' => '11111'
), $atts));
ob_start();
get_template_part('test');
return ob_get_clean();
}
add_shortcode('test', 'ctest_shortcode');
我尝试在模板文件测试中使用echo $ a,但未显示任何内容
<?phpif ( ! defined( 'ABSPATH' ) ) {exit( 'Direct script access denied.' );}
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'mynews',
'tax_query' => array(
array(
'taxonomy' => 'newstypes',
'field' => 'tag_ID',
'terms' => array('$a') // shortcode parameter $a variable
),),));
if( $posts ): ?>
<?php foreach( $posts as $post ):
setup_postdata( $post );?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><
<?php endforeach; ?>
<?php endif; wp_reset_postdata(); ?>
这是模板部分