Php Wordpress短代码未传递变量
这是密码。它只显示一个图像,而不考虑快捷码使用的类别名称Php Wordpress短代码未传递变量,php,wordpress,shortcode,Php,Wordpress,Shortcode,这是密码。它只显示一个图像,而不考虑快捷码使用的类别名称 <?php // Create Slider function wptuts_slider_template($category_name) { global $post; // Query Arguments $args = array( 'post_type' => 'slides', 'order' => 'ASC',
<?php
// Create Slider
function wptuts_slider_template($category_name) {
global $post;
// Query Arguments
$args = array(
'post_type' => 'slides',
'order' => 'ASC',
'category_name' => $category_name
);
// The Query
$the_query = new WP_Query( $args );
// Check if the Query returns any posts
if ( $the_query->have_posts() ) {
// Start the Slider ?>
<ul class="slides <?php wp_title(); ?> <?php echo $category_name ?>" data-options="animation:fade;
pause_on_hover:true;
resume_on_mouseout: true;
timer_speed:3000;
animation_speed:500;
navigation_arrows:true;
bullets:true;
slide_number:false;
next_on_click:true;
timer: true;" data-orbit>
<?php
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<?php // Check if there's a Slide URL given and if so let's a link to it
if ( get_post_meta( get_the_id(), 'wptuts_slideurl', true) != '' ) { ?>
<a href="<?php echo esc_url( get_post_meta( get_the_id(), 'wptuts_slideurl', true ) ); ?>">
<?php }
// The Slide's Image
echo get_the_post_thumbnail();
// Close off the Slide's Link if there is one
if ( get_post_meta( get_the_id(), 'wptuts_slideurl', true) != '' ) { ?>
</a>
<?php } ?>
</li>
<?php endwhile; ?>
</ul><!-- .slides -->
<?php }
// Reset Post Data
wp_reset_postdata();
}
// Slider Shortcode
function wptuts_slider_shortcode($atts) {
extract(shortcode_atts(array(
"category_name" => 'other',
), $atts));
ob_start();
wptuts_slider_template($category_name);
$slider = ob_get_clean();
return $slider;
}
add_shortcode( 'slider', 'wptuts_slider_shortcode' );
您将在shortcode函数中提取到$atts['other']。你应该更新
wptuts_slider_template($category_name);
到
在同一个函数中正确传递数据。您是否像这样使用您的快捷码[slider category\u name=“我们的超级类别”]
?是的,这是快捷码格式。将'posts\u per\u page'=>-1
添加到您的$args。。。然后试试看。目前你还没有定义它可以获得的帖子数量。。。也许这就是问题所在,那是不可能的。我之前已经定义了5,但它也不适用于-1。谢谢你迄今为止的帮助。
wptuts_slider_template($atts['other']);