【发布时间】:2020-05-12 14:09:18
【问题描述】:
我需要在滑块中发布两个特定分类中的文章和页面。我试图合并 $args 和 $args2 但它给了我一个错误。谁能告诉我如何正确编写代码?谢谢!
这是代码:
<?php
$slider_counter = 0;
$args = array(
'post_type' => 'post',
'category_name' => 'slider'
);
$args2 = array(
'post_type' => 'page',
'tax_query' => array(
array(
'taxonomy' => 'my_taxonomy',
'field' => 'slug',
'terms' => 'slider'
)
)
);
$merged_query_args = array_merge( $args, $args2 );
$query_slider = new WP_Query ( $merged_query_args );
while ( $query_slider->have_posts() ) :
$query_slider->the_post(); ?>
<?php $slider_counter++ ;?>
<?php $slider_image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id( $post ->ID ), 'slider_img' );?>
<div class="swiper-slide <?php if ($slider_counter ==1) { echo 'active'; } ?>">
<a href="<?php the_permalink(); ?>"><img src="<?php echo $slider_image_attributes[0]; ?>" class="d-block w-100" alt="..."></a>
<div class="carousel-caption d-none d-md-block">
<div class="dispaly-3"><a href="<?php the_permalink(); ?>" class="slider-a"><?php the_title(); ?></a></div>
</div>
</div>
<?php endwhile;
wp_reset_query();
wp_reset_postdata(); ?>
【问题讨论】:
-
你的错误是什么?
-
滑块从页面中消失。
标签: php wordpress slider custom-taxonomy article