Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tạo một bài dính trên blog thử nghiệm của bạn và hãy xem tại trang chủ của trang web. Bạn sẽ thấy văn bản thêm vào các bài dính, và sau này nên được chuyển đến đầu của The Loop. Bạn có thể thấy điều này trong các ảnh chụp màn hình sau đây: | Chapter 3 div class sticky-announcer p This post is sticky. p div php Create a sticky post on your test blog and take a look at your site s front page. You should see text appended to the sticky post and the post should be moved to the top of The Loop. You can see this in the following screenshot How it works. The is_sticky function checks the currently-active post to see if it is a sticky post. It does this by examining the value retrieved by calling get_option sticky_posts which is an array and trying to find the active post s ID in that array. The Loop In this case if the post is sticky then the sticky-announcer div is output with a message. However there is no limit to what you can do once you ve determined if a post is sticky. Some ideas include Displaying a special icon for sticky posts Changing the background color of sticky posts Adding content dynamically to sticky posts Displaying post content differently for sticky posts Creating multiple loops in a single template In advanced themes there are often situations where you would want to display multiple Loops consisting of posts with different criteria. When doing so you should make sure not to alter the normal default Loop or else some template tags will not work appropriately. How to do it. First decide what kind of Loops you want to create. Perhaps you want to create two Loops based on different categories. Perhaps one Loop should have featured posts while the other has the default posts based on the page URL. For this example we re going to create two category Loops. To create the two category Loops you need to create two separate instances of the WP_Query class. Copy the following code snippet into one of your template files php query1 new WP_Query array cat get_cat_ID aciform if query1- have_posts h1 Aciform Posts h1 php while query1- have_posts query1- the_post h2 php the_title h2 php echo hr query2 new WP_Query array cat get_cat_ID Cat B if query2- have_posts h1 Cat B Posts h1 php while query2- .