Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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_Pagination - Fatal编程技术网

Php WordPress断页

Php WordPress断页,php,wordpress,pagination,Php,Wordpress,Pagination,我的自定义贴子页面上的分页工作正常,但在添加了几篇贴子后,它被破坏了——旧的贴子链接不再工作 请建议我如何修理它?我尝试过禁用插件,更改永久链接,以及几乎任何我能在WordPress Codex上找到的东西 以下是我的分页查询: <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array('post_type' => 'press' , 'posts_per_page' =&g

我的自定义贴子页面上的分页工作正常,但在添加了几篇贴子后,它被破坏了——旧的贴子链接不再工作

请建议我如何修理它?我尝试过禁用插件,更改永久链接,以及几乎任何我能在WordPress Codex上找到的东西

以下是我的分页查询:

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('post_type' => 'press' , 'posts_per_page' => 50 , 'paged' => $paged);
query_posts( $args );
/*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
//query_posts ( $args );//query_posts($query_string . '&caller_get_posts=6&posts_per_page=12');
?>
<ul class="griditemleft clear">
    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
        <?php if (has_post_thumbnail() ) : ?>
            <li>
                <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a>
                <h2 class="press-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
            </li>
        <?php endif; ?>
    <?php endwhile; ?>
</ul>

<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>

<?php else : ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>


关于你想要实现的目标还不完全清楚,但我想你应该仔细看看

在查询中指定硬编码偏移量可以也将中断分页,因为WordPress在内部使用偏移量来计算和处理分页

为了绕过这个限制,您需要编写一些额外的代码来手动处理分页;您需要检测循环是否有其他页面,然后动态计算当前页面的适当偏移量

控制自定义分页的代码将全部出现在functions.php文件中,而不是模板page.php中。您可以设置初始偏移量,以及重新定义每页的帖子数。上面的codex链接上显示了特定的样本

您将在运行查询之前通过添加操作

   add_action('pre_get_posts', 'myprefix_query_offset', 1 );
您必须通过

   add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );