当我转到 page/2 时,wordpress 中的分页抛出错误 404

问题描述 投票:0回答:0

我有一个问题。

我尝试了很多解决方案,其中一些:

  1. 清除任何额外类别的永久链接
  2. 禁用所有插件并一一重新激活。
  3. 在functions.php中添加此代码
function modify_product_cat_query($query) {
    if (!is_admin() && $query->is_tax("ford_escort")){
        $query->set('posts_per_page', 10);
    }
}
add_action( 'pre_get_posts', 'modify_product_cat_query' );

这一切都不起作用......第一页生成的 url 是 http://localhost:10004/page/2 正如你所看到的,我在中间没有看到任何额外的类别...... 你能帮我吗? 我正在使用最新版本的 WordPress 和 PHP 8.1.9

我有自定义分类的代码,我需要对其进行分页。

<?php
    $paged = get_query_var('ford_escort') ? get_query_var("") : 1;

    // Custom query arguments for pagination
    $args = array(
    'post_type' => 'escort',
    'posts_per_page' => 50,
    'paged' => $paged,
     );

    // Create a custom query
    $custom_query = new WP_Query($args);

    // Now you can loop through the posts
    if ($custom_query->have_posts()) {
    while ($custom_query->have_posts()) {
        $custom_query->the_post();
        // Display post content here
        echo '<h2>' . get_the_title() . '</h2>';
    }
    wp_reset_postdata(); // Restore original post data

    // Display pagination links
    echo paginate_links(array(
        'total' => $custom_query->max_num_pages,`your text`
        'current' => $paged,
        'prev_next' => false,
        'prev_text' => __('&laquo; Previous'),
        'next_text' => __('Next &raquo;'),
    ));

   }
   ?>

页面出现,但当我选择任何页面时,我收到 404 页面错误。

php wordpress pagination custom-post-type taxonomy
© www.soinside.com 2019 - 2024. All rights reserved.