Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想使用PHP在WordPress中添加分页。但我不知道';我不知道如何在自定义插件中做到这一点_Php_Wordpress - Fatal编程技术网

我想使用PHP在WordPress中添加分页。但我不知道';我不知道如何在自定义插件中做到这一点

我想使用PHP在WordPress中添加分页。但我不知道';我不知道如何在自定义插件中做到这一点,php,wordpress,Php,Wordpress,嘿,我将这段代码添加到WordPress页面,这个插件获取特定类别的所有帖子,它工作正常,我想在这段代码上添加分页,但我不知道怎么做 <?php $catquery = new WP_Query( 'cat=124&posts_per_page=10' ); while($catquery->have_posts()) : $catquery->the_post()?><div class="main-box"> <div class="p

嘿,我将这段代码添加到WordPress页面,这个插件获取特定类别的所有帖子,它工作正常,我想在这段代码上添加分页,但我不知道怎么做

<?php
 $catquery = new WP_Query( 'cat=124&posts_per_page=10' );
 while($catquery->have_posts()) : $catquery->the_post()?><div class="main-box">

<div class="photos">
    <ul class="photo-data">
               <li><?php  the_post_thumbnail();  ?></li>
    </ul>
</div>
<div class="title_desc">


<ul>
     <li style="list-style-type: none;">
          <h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
              <?php  $content = get_the_content();
              echo substr($content, 0, 50);  ?>

           <a href="<?php the_permalink() ?>" rel="bookmark">...Read More</a>
     </li>
</ul>


</div></div><?php endwhile; ?>`

`
试试这个代码

<?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $catquery = new WP_Query( 'cat=7&posts_per_page=5&paged='.$paged);
        global $wp_query;
        $tmp_query = $wp_query;
        $wp_query = null;
        $wp_query = $catquery;
        while($catquery->have_posts()) : $catquery->the_post()?>
        <div class="main-box">
            <div class="photos">
                <ul class="photo-data">
                    <li>
                        <?php  the_post_thumbnail();  ?>
                    </li>
                </ul>
            </div>
            <div class="title_desc">
                <ul>
                    <li style="list-style-type: none;">
                        <h3><a href="<?php the_permalink() ?>" rel="bookmark">
                            <?php the_title(); ?>
                        </a></h3>
                        <?php  $content = get_the_content();
                        echo substr($content, 0, 50);  ?>
                        <a href="<?php the_permalink() ?>" rel="bookmark">...Read More</a>
                    </li>
                </ul>
            </div>
        </div>
        <?php endwhile; ?>
        <div class="pagination">
          <?php previous_posts_link('&laquo; Newer') ?>
          <?php next_posts_link('Older &raquo;') ?>
        </div>


Hey iPraxa LLC感谢您的回复,但您的回复无效。嗨,Manish Panchal,我已经更新了代码。请检查这个,它对我来说很好用。