tailieunhanh - Hướng dẫn tạo themes cho wordpress part 26
Làm thế nào nó hoạt động . Phần quan trọng nhất của công thức này là hình ảnh chức năng xác định ngẫu nhiên. Bạn làm cho các chức năng có sẵn trong chủ đề của bạn bằng cách tạo ra nó trong file rằng WordPress tải như một phần của quá trình khởi động của nó. Thứ nhất, chức năng kiểm tra wptc_get_header_image để đảm bảo rằng các thư mục thích hợp tồn tại trong chủ đề của bạn và có sẵn để đọc | Chapter 12 After you do all of this you get a nice random header. The following screenshots show a random header image Layout How it works. The most important part of this recipe is the random image determination function. You make the function available throughout your theme by creating it in the file that WordPress loads as part of its startup process. First the wptc_get_header_image function checks to make sure that the appropriate directory exists in your theme and is available for reading. After these conditions are verified PHP opens the header-images directory and iterates over each file in the directory. The filenames . and . are excluded because they have special meanings in the context of the file system and do not need to be considered in this case. Every other filename in the directory is verified to be an image and if it is it s added to an array of header image possibilities. After the array of possible image URLs is complete the function verifies that at least one item is present in the array. If the array is not empty a random key is retrieved from the array using array_rand and the array item for that key is returned. If the array does not have any items in it then the false literal is returned. Chapter 12 On the front-end directly above the markup for the header you call wptc_get_header_ image to get a random URL for an image. If an image URL is returned you populate the value of the style variable with the appropriate background-image declaration. Otherwise the style variable remains undeclared. In the declaration for the header div you add the contents of the style variable as an inline style in order to make the background image of the header change at render time. When the page is displayed the image is fetched and placed in the background of the header div and the header text in this case the blog s name renders on top of the image. Making theme components drag-and-drop The best websites provide means for their users to shape a
đang nạp các trang xem trước