0

I have this php code for wordpress random post plugin:

<?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 ?>

I wanna know what is the the meaning of the code 'offset' => 1.i already understand to others such as:

  • Numberpost - how many post you would like to be displayed?
  • Orderby – randomly select from the list of our blog post.
  • Post_status – selects only the blog post which is on Publish status.
  • Offset - ???

can someone define this for me.

4

1 回答 1

8

The offset is used for pagination. From the docs:

offset (int) - number of post to displace or pass over. Note: Setting offset parameter will ignore the paged parameter.

于 2013-01-12T14:33:42.600 回答