
內容簡介
這個外掛會加入兩個額外的 SQL 查詢,將原始的資料樣本 $wp_query->posts 與所有的 meta 欄位、所有的檔案和圖片結合起來,對於每一張圖片,會形成直接連結到小型、中型和大型圖片的網址。無需使用函數 the_post_thumbnail 和 get_post_meta。
運作方式
讓我們假設我們前往部落格首頁,WordPress 會給我們一個最新 10 篇文章的清單。讓我提醒一下,這些已經在全域物件中的陣列 $wp_query->posts 中了。讓我們從創建 ID 列表開始(將每個文章記錄存在資料庫中的編號數)。
形成第一個 SQL 查詢:
$query = “SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN(’21’,’29’,’30’,’35’,’38’,’42’,’46’,’48’,’49’,’55’) AND $wpdb->posts.post_parent
AND $wpdb->posts.post_type = ‘attachment'”;
一個正常的翻譯是「尋找編號為('21 '、'29 '、'30 '、'35 '、'38 '、'42 '、'46 '、'48 '、'49 '、'55')的所有子項目」。所需類型的記錄是「附件」。換句話說,我們找到了我們為 10 篇文章下載的所有檔案(附件)。
再次形成 ID 列表:前 10 個 ID 記錄和檔案(附件)的 ID。檔案(附件)作為普通的記錄都存在 wp_posts 這個表中。
現在我們使用函數 update_meta_cache:
$all_meta = update_meta_cache(‘post’, $ar_all_id);
$ar_all_id-這裡是原始的記錄和檔案(附件)
這樣一切就進入了快取,後續的調用 get_post_meta 將從快取中提取值。其餘的都是技術問題 - 資料必須小心整理,不要混淆任何內容。所有的 meta 欄位都被添加到 $post->meta 陣列中,並將檔案添加到 $post->files 陣列中,並立即按照編號順序對文件進行排序(下載時,可以指定排序順序)。
此外,對於每個檔案,如果它是圖片,就會計算縮略圖的完整路徑:小型(縮略圖)、中型(中等大小)和完整的圖片。
WordPres 4:
預設篩選器僅使用 is_main_query() 連接到主查詢。
不適用於 is_admin() 或 is_page()。
主頁
俄文頁面
簡要的 Markdown 示例
更多 PHP 代碼示例
更多示例
外掛標籤
開發者團隊
原文外掛簡介
The pluginplug-in, with two additional SQL queries, joins the original data sample $wp_query->posts all meta fields, all files and images, for each image the direct url to small, medium, and large image is formed. There’s no need to use functions the_post_thumbnail and get_post_meta.
How it works
So let’s say we go to the home page of our blog, WordPress gives us a list of the latest 10 records. Let me remind you these are already in the global object in the array $wp_query-> posts. Let’s begin from creating a list of ID (number of records to which they are stored in the database).
Form the first SQL query:
$query = “SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN(’21’,’29’,’30’,’35’,’38’,’42’,’46’,’48’,’49’,’55’) AND $wpdb->posts.post_parent
AND $wpdb->posts.post_type = ‘attachment'”;
A normal translation is «find all the child entries for entries with the numbers (’21 ‘, ’29?, ’30 ‘, ’35?, ’38 ‘, ’42?, ’46 ‘, ’48?, ’49 ‘, ’55 ‘)». And the type of records required to be «attachment». That is, in short, we find all the files (attachment) which we downloaded for our 10 entries.
Again we form a list of ID: the first 10 ID entries and add the ID of files (attachments). Attachments as ordinary records are stored in one table – wp_posts.
Now we use the function update_meta_cache:
$all_meta = update_meta_cache(‘post’, $ar_all_id);
$ar_all_id – here are the original recordings and attachments
So everything just gets in the cache and subsequent calls get_post_meta will derive value from the cache. The rest is a matter of technique – the data must be carefully arranged, not mixing anything up. All meta fields are added to the $post->meta array, and files into an $post->files array and files are immediately sorted by number order (when downloading it, you can specify the sort order).
In addition, for each file, if it is an image, the full path to the thumbnails is calculated: small (thumbnail), average (medium) and the complete picture (full).
WordPres 4:
The default filter is only connected to the main query using is_main_query().
Does not work in is_admin() or is_page().
Home page
Русская страница
A brief Markdown Example
More PHP code Examples
Больше примеров
