使用循环检索wordpress帖子

使用循环检索wordpress帖子,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我需要实现一个滑块,将显示从一个特定的类别在每个幻灯片4后缩略图。为此,我写了这样一篇文章: <ul class= "videoSlider"> <?php $pStart = 0; $flag = true; while ($flag) {

我需要实现一个滑块,将显示从一个特定的类别在每个幻灯片4后缩略图。为此,我写了这样一篇文章:

<ul class= "videoSlider">
                            <?php
                            $pStart = 0;
                            $flag = true;

                            while ($flag) {

                                query_posts('cat=14&posts_per_page=4&offset='.$pStart);

                                $pStart = + 4;
                            ?>


                                <li>
                                <?php
                                if (have_posts ()) {

                                    while (have_posts ()) {
                                        the_post();
                                ?>
                                        <div onclick="something()">

                                    <?php echo the_post_thumbnail(array(215, 190)); ?>
                                         </div>

                                <?php
                                    }
                                } else {
                                    $flag = false;
                                }
                                ?>
                            </li>


                            <?php

                            wp_reset_query();

                            } ?>
我需要jquery滑块的结构如下:

                <ui>
                      <li>
                        <div>
                            thumb 1
                        </div>
                        <div>
                           thumb 2
                        </div>
                        <div>
                            thumb 3
                        </div>
                        <div>
                            thumb 4
                        </div>
                    </li>


                    <li>
                        <div>
                            thumb 5
                        </div>
                        <div>
                           thumb 6
                        </div>
                        <div>
                            thumb 7
                        </div>
                        <div>
                            thumb 8
                        </div>
                    </li>

                </ul>

  • 拇指1 拇指2 拇指3 拇指4
  • 拇指5 拇指6 拇指7 拇指8
  • 但由于某些原因,代码不起作用!看起来在生成几个列表后,代码执行并没有停止,浏览器挂起。我是否以错误的方式使用了该函数:“
    query\u posts('cat=14&posts\u per\u page=4&offset=”。$pStart)
    ”?
    我应该如何实现它呢?

    如果你有很多帖子,那么外部的
    while
    循环将继续进行,直到每个帖子都被查询到,一次两篇

    在我看来,你让事情变得复杂了,所以我要做的是

    global $wp_query;
    query_posts('cat=14');
    
    if ( have_posts() ):
    
        $last_post = $wp_query->post_count - 1; // index for the last post
        $counter = 0;
    
        echo '<ul class= "videoSlider">';
    
            while ( have_posts() ):
    
                the_post();
    
                if ($counter === 0)
                    echo '<li>';
    
                echo '<div onclick="something()">';
                the_post_thumbnail(array(215, 190));
                echo '</div>';
    
                if ($counter === 3 || $last_post == $wp_query->current_post) {
                    $counter = 0;
                    echo '</li>'; // close the tag every 4th item, or if we're at the end of the loop
    
                } else {
                    $counter++;
                }
    
    
            endwhile;
    
        echo '</ul>';
    
    endif;
    
    global$wp\u查询;
    查询职位('cat=14');
    如果(have_posts()):
    $last\u post=$wp\u query->post\u count-1;//最后一篇文章的索引
    $counter=0;
    echo'
      ; while(have_posts()): _post(); 如果($counter==0) 回音“
    • ”; 回声'; _post_缩略图(数组(215190)); 回声'; 如果($counter==3 | |$last|u post==wp|u query->current|u post){ $counter=0; echo“
    • ”;//每四项关闭一次标记,或者如果我们在循环的末尾 }否则{ $counter++; } 结束时; 回声“
    ”; endif;
    太棒了!它工作得很好!我并没有这样想:)注意:在我的第一个方法中,我尝试了6篇文章,所以我不明白为什么要花那么长时间并冻结浏览器!