qq_252007313 2022-05-15 20:49 采纳率: 0%
浏览 31
已结题

php列表改为随机加载

php列表顺序加载改为随机加载

        <div class="tab-list active">
            <ul class="post-loop post-loop-default cols-4">
                <?php
                $exclude = isset($options['newest_exclude']) && is_array($options['newest_exclude']) ? $options['newest_exclude'] : array();
                $arg = array(
                    'posts_per_page' => $per_page,
                    'ignore_sticky_posts' => 0,
                    'post_type' => 'post',
                    'post_status' => array( 'publish' ),
                    'category__not_in' => $exclude
                );
                $posts = new WP_Query($arg);
                if( $posts->have_posts() ) { while ( $posts->have_posts() ) { $posts->the_post(); ?>
                    <?php get_template_part( 'templates/loop' , 'default-sticky' ); ?>
                <?php } } wp_reset_postdata(); ?>
            </ul>
            <?php if($posts->max_num_pages>1){ ?>
                <div class="load-more-wrap">
                    <div class="btn load-more j-load-more" data-per_page="<?php echo $per_page;?>" data-exclude="<?php echo implode(',', $exclude);?>"><?php _e('Load more posts', 'wpcom');?></div>
                </div>
            <?php } ?>
        </div>
  • 写回答

2条回答 默认 最新

  • blackoon88 2022-05-15 22:49
    关注

    shuffe()函数 ,打乱数组中的元素位置

     $arr = [1, 2, 3, 4, 5];
     var_dump( shuffle( $arr ) ) ;
     print_r( $arr );
    
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月17日
  • 修改了问题 5月15日
  • 创建了问题 5月15日