【问题标题】:Skip First Post in Every Page in WordPress在 WordPress 的每个页面中跳过第一个帖子
【发布时间】:2021-03-21 16:17:16
【问题描述】:

我正在使用 WordPress 自定义查询,我想跳过每个页面上的第一篇文章,即第 1、2、3 页... 我有一个问题,但不知道如何只跳过第一个帖子。

Suppose there are 19 posts id 1,2,3 ... 19,
I want 1st post having id 19 should be ignore on every page with posts_per_page => 6
So, on page 1 posts of these id's will be shown :  18,17,16,15,14,13 and
on page 2 posts of these id's will be shown :  12,11,10,9,8,7 and 
on page 3 posts of these id's will be shown :  6,5,4,3,2,1 

在这里我们可以看到第一个帖子(id => 19)在每个页面上都被跳过,这就是我想要的,我该如何实现?

查询:-

$catID = 13;
  $page = $_POST['page'];
  $output = '';
  $total_pages = 0;

    $args = [
        'posts_per_page' => 6,
        'cat' => $catID,
        'order' => 'DESC',
        'paged' => $page,
    ];

  $posts = new WP_Query($args);

注意:我使用了 offset => 1 但这不是我想要的。

【问题讨论】:

    标签: wordpress posts


    【解决方案1】:

    尝试添加偏移量

        $catID = 13;
          $page = $_POST['page'];
          $output = '';
          $total_pages = 0;
        
            $args = [
                'posts_per_page' => 6,
                'cat' => $catID,
                'order' => 'DESC',
                'paged' => $page,
                'offset' => 1
            ];
    
      $posts = new WP_Query($args);
    

    【讨论】:

    • 正如我上面所说的,我也使用了这个,但是当我到达第 2 页或第 3 页时,我得到相同的帖子,似乎分页不起作用
    • 没问题,感谢您的时间和精力
    猜你喜欢
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 2017-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多