WordPress calls the sticker article code

Today, when doing wordpress theme, just to use the call of the top articles. Here to share with you WordPress how to add the top articles.


Add a sticker article:

1, we can see the current editor of the article on the right side of a public degree: release editor, click on the editor, check the “Zhiding this article to the home page”, then open the blog you can see the top of the state.

2, when the article was released, then we can click the blog background menu menu under the “Edit” option, enter the article list, the mouse moved to the need to stick the article, under the title of the article will show “edit”, “fast Edit “,” Delete “,” View “four options, click the” Quick Edit “option

3, in the quick editing, you can edit the title, label, alias, classification and other operations, at the same time here can also be the top of the operation of the article, in the “keep this article Zhiding” in front of the small box tick, and then click to update the article , Then the article on the blog home to keep the top state.

4, update the article, open the blog home page will find the state of the top of the article


Call WordPress Top Articles List:

In the need to call WordPress Zhiding articles directly add the following code:

  1. <?php
  2. $sticky = get_option(‘sticky_posts’);
  3. rsort( $sticky );
  4. $sticky = array_slice$sticky, 0, 5);
  5. query_posts( array( ‘post__in’ => $sticky, ‘caller_get_posts’ => 1 ) );
  6. if (have_posts()) :
  7. while (have_posts()) : the_post();
  8. ?>
  9. here is the content want to show
  10. <?php endwhileendif; ?>


Please modify the required place according to the actual code. When there is no sticked article, the latest five articles.