Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable Ambil dan Dapatkan ID Wordpress Posting Di luar Loop sebagai Variabel PHP
In WordPress, each post has unique anchor identifier in the form of numeric post ID. Di Wordpress, setiap posting memiliki jangkar pengenal unik dalam bentuk angka posting ID. When inside the Loop, where WordPress processes and displays each of the posts to be displayed on the current page and formats them according to how they match specified criteria within The Loop tags, template tag the_ID can be used to easily display the post's ID inside the post. Ketika di dalam Loop, di mana proses Wordpress dan menampilkan setiap posting yang akan ditampilkan pada halaman ini dan format mereka menurut bagaimana mereka sesuai dengan kriteria tertentu dalam The Loop tag, tag template the_ID dapat digunakan untuk dengan mudah menampilkan posting di dalam KTP post. Alternatively, inside the the_content filter, declare $id global and use $id to retrieve the post ID. Atau, di dalam the_content filter, menyatakan $ id global dan menggunakan $ id untuk mengambil pos ID.
the_ID template tag can be used in the following format: the_ID template tag dapat digunakan dalam format berikut:
<?php the_ID(); ?> <? php the_ID ();?>
Outside the Loop or out of the context of the post, such as in header of footer and even sidebar area in the templates of WordPress's blog, the_ID() cannot be used as a function. Di luar Loop atau keluar dari konteks pos, seperti di header sidebar footer dan bahkan wilayah dalam template dari Wordpress's blog, the_ID () tidak dapat digunakan sebagai fungsi. Instead, $post->ID will be used to return the post ID (the syntax can also be used inside the Loop of the post by declaring $post as global). Sebaliknya, $ post-> ID akan digunakan untuk mengembalikan pos ID (sintaks juga dapat digunakan di dalam Loop pos dengan mendeklarasikan $ pos sebagai global). $post is a global object that holds various information about the posts displayed on the page. $ posting adalah obyek global yang menyimpan berbagai informasi tentang posting ditampilkan pada halaman. So $post->ID will return the post ID of the post. Jadi $ post-> ID akan mengembalikan ID pos pos. It the $post is used inside a function, the $post has to be declared as a global variable. Ini yang $ pos digunakan di dalam fungsi, yang $ pos harus dinyatakan sebagai variabel global. For example: Contoh:
// Works inside of the Loop
function function_name() {
global $post;
$thePostID = $post->ID;
}
or: atau:
// Works in single post outside of the Loop
function function_name() {
global $wp_query;
$thePostID = $wp_query->post->ID;
}
$post->ID can be called directly outside of the Loop too in a single post template, such as <?php echo $post->ID ?> will print display the post's ID number. $ post-> ID dapat disebut langsung di luar Loop terlalu dalam satu template posting itu, seperti <? php echo $ post-> ID?> akan mencetak menampilkan posting dari nomor ID.
In the multiple posts view page such as index page or archive page, it's possible to retrieve the get the latest or earliest post ID of all the posts displayed on the page by using an ORDER BY clause to order the posts by date, and then set the number of record to LIMIT 1. Dalam posting beberapa halaman tampilan seperti halaman index atau halaman arsip, mungkin untuk mengambil mendapatkan posting terbaru atau awal ID dari semua posting yang ditampilkan pada halaman dengan menggunakan klausa ORDER BY untuk memesan posts by tanggal, dan kemudian menetapkan jumlah catatan untuk LIMIT 1.
Just for example, and there are various way to use the query: Hanya untuk contoh, dan ada berbagai cara untuk menggunakan query:
//Get the latest post ID number / / Get the latest post nomor ID
$post->ID ORDER BY post_date ASC LIMIT 1 $ post-> ID ORDER BY post_date ASC LIMIT 1
//Get the earliest post ID number / / Dapatkan nomor ID posting awal
$post->ID ORDER BY post_date DESC LIMIT 1 $ post-> ID ORDER BY post_date DESC LIMIT 1
IMPORTANT : The page is machine translated and provided "as is" without warranty. PENTING: Halaman ini adalah mesin diterjemahkan dan diberikan "sebagaimana adanya" tanpa jaminan. Machine translation may be difficult to understand. Terjemahan mesin mungkin sulit untuk mengerti. Please refer to Silakan merujuk ke original English article artikel asli bahasa Inggris whenever possible. bila memungkinkan.
Related Articles Artikel Terkait
- Paginating or Split WordPress Post or Page with NextPage in WordPress Not Working Wordpress Paginating atau Split Post atau Page dengan Nextpage di Wordpress Not Working
- Disable and Turn Off Post Revisions Tracking in WordPress 2.6 or Above Nonaktifkan dan Nonaktifkan Pelacakan Revisi Posting di WordPress 2.6 atau Above
- How to Delete Existing WordPress Post Revisions Stored/Saved Cara Hapus ada Stored Revisi Wordpress Posting / Saved
- How To Store Every Post Revisions on Each Auto-Save in WordPress with Limit on Versions Count Cara Store Revisi Setiap Posting di Setiap Auto-Simpan di Wordpress dengan Versi Limit Count
- Adding Extra More Fields to WordPress Write/Edit Post/Page Right Column Menambahkan Extra More Fields ke Wordpress Write / Edit Post / Page Right Column
- How to Change the Frequency or Interval WordPress Auto Saves An Editing Post or Page Bagaimana Mengubah Frekuensi atau Interval WordPress Auto Saves An Editing Post atau Page
- How to Wrap AdSense Ads Around and Inline Beside Blogger Post Content Cara Bungkus Iklan AdSense Sekitar dan Inline Selain Konten Blogger Posting
- Move Blogger Inline Ads Between Posts to Inside Within Post Position Pindahkan Blogger Inline Iklan Di Antara Posting ke Posting Dalam Posisi
- Place AdSense Ad Unit In Various Positions Inside Within Blogger Post Contents Menempatkan AdSense Unit Iklan Various Positions Di Dalam Blogger Dalam Isi Posting
- How to Display Elements (Ads) Only On (Or Only Not At) Individual Single Post Item View Bagaimana Tampilan Elemen (Iklan) Hanya Aktif (Atau Hanya Not At) Masing-masing Item View Single Post










































November 7th, 2009 03:41 7 November 2009 03:41
Hi, Hai,
I'm trying to modify a custom post-new.php in the admin area and need to access the post_id of a post that I'm currently editing and that has not yet been published. Saya mencoba untuk memodifikasi pasca kustom new.php di admin area dan perlu mengakses sebuah pos post_id bahwa aku sedang mengedit dan yang belum diterbitkan. Any idea how I could do that? Tahu bagaimana aku bisa melakukan itu?
Thanks Terima kasih
October 30th, 2009 02:22 30 Oktober 2009 02:22
Thanks, this was super-helpful and easy to understand! Terima kasih, ini super-membantu dan mudah dimengerti! I love code samples! Saya suka contoh kode!