【问题标题】:What is the meaning of 'OFFSET' => 1 (WordPress)'OFFSET' => 1 是什么意思(WordPress)
【发布时间】:2013-01-12 14:30:29
【问题描述】:

我有这个用于 wordpress 随机帖子插件的 php 代码:

<?php
global $post;
$tmp_post = $post;
$args = array( 'numberposts' => 5, 'orderby' => 'rand', 'post_status' => 'publish', 'offset' => 1);
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
    <li><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2><p><?php the_excerpt(); ?>
    </p></li>
<?php endforeach; ?>
</ul>
<?php $post = $tmp_post; // reset the $post to the original ?>

我想知道代码'offset' =&gt; 1的含义是什么。我已经理解了其他人,例如:

  • Numberpost - 您希望显示多少个帖子?
  • Orderby – 从我们的博文列表中随机选择。
  • Post_status – 仅选择处于发布状态的博文。
  • 偏移量 - ???

谁能帮我定义一下。

【问题讨论】:

  • 偏移量是您的起点。例如,如果它设置为 10,那么它将从表格​​的第 10 行开始。它经常用于分页。
  • 很抱歉,我无法理解。所以如果我将它设置为 1,它将从什么开始?
  • @krike,我没有检查,但计数可能从 0 开始。所以偏移量 10 将从第 9 行开始。
  • 上面的代码是显示wordpress随机的博客文章,这意味着将偏移量设置为1是什么意思? 1 表示它将从什么开始?

标签: php wordpress


【解决方案1】:

偏移量用于分页。来自docs

offset (int) - 要替换​​或跳过的帖子数。注意:设置偏移量参数会忽略分页参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    • 2016-11-18
    • 2019-11-19
    • 2016-09-20
    相关资源
    最近更新 更多