【问题标题】:How to fix wordpress pagination redirect?如何修复wordpress分页重定向?
【发布时间】:2020-12-14 09:00:06
【问题描述】:

我在 wordpress category.php 页面中使用分页。一切都很好,但是当我点击下一页时出现以下错误

Template is missing. Standalone themes need to have a index.php template file. Child themes need to have a Template header in the style.css stylesheet.

我的网址有点像

https://test.com/category/cat_name/page/2/

这是我的代码:

    $cat_name = $category->name;
      $cat_id   = get_cat_ID( $cat_name );
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
      $temp = $wp_query;
      $wp_query = null;
      $wp_query = new WP_Query();
      $wp_query->query('showposts=1&post_type=post&paged='.$paged.'&cat='.$cat_id);
      while ($wp_query->have_posts()) : $wp_query->the_post(); 
/// loop here
<?php endwhile; ?>

分页代码:

<?php
  global $wp_query;
 
  $big = 999999999; // need an unlikely integer
  echo '<div class="custom-pagination">';
    echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'prev_text' => __('Previous'),
    'next_text' => __('Next'),
    'current' => max( 1, get_query_var('paged') ),
    'total' => $wp_query->max_num_pages
    ) );
  echo '</div>';
?>      

我应该在 htaccess 文件或 function.php 中添加一些代码以在 category.php 中重定向吗?

【问题讨论】:

    标签: php wordpress pagination


    【解决方案1】:

    我自己得到了答案。我需要在仪表板的阅读部分更改Blog pages show at most。我在Blog pages show at most中设置了相同数量的showposts,即1。

    【讨论】:

      猜你喜欢
      • 2022-01-22
      • 2019-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 2021-06-22
      • 1970-01-01
      • 2015-05-25
      相关资源
      最近更新 更多