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.


27 Responses to “Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable” 27 Responses to "Ambil dan Dapatkan ID Wordpress Posting Di luar Loop sebagai Variabel PHP"

Pages: [2] Pages: [2] 1 1 » » Show All Tampilkan Semua

  1. Konisto Konisto
    November 7th, 2009 03:41 7 November 2009 03:41
    27 27

    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

  2. Blake Blake
    October 30th, 2009 02:22 30 Oktober 2009 02:22
    26 26

    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!

Pages: [2] Pages: [2] 1 1 » » Show All Tampilkan Semua

Leave a Reply Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> Anda dapat menggunakan tag ini: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime = ""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. Berlangganan ke fitur komentar telah dinonaktifkan. To receive notification of latest comments posted, subscribe to Untuk menerima pemberitahuan dari komentar terbaru diposting, untuk berlangganan My Digital Life Comments RSS feed My Digital Life Komentar RSS feed or atau register to receive mendaftar untuk menerima new comments in daily email digest. komentar baru di email digest harian.
Custom Search

New Articles Artikel Baru

Incoming Search Terms for the Article Cari Syarat masuk untuk Artikel

wordpress get post id wordpress bisa posting - -- wordpress post id posting wordpress - -- wordpress get page id wordpress Halaman mendapatkan id - -- post id wordpress posting wordpress - -- $post->ID $ post-> ID - -- wordpress get current page id mendapatkan halaman wordpress id - -- get post id wordpress mendapatkan posting wordpress - -- get post id mendapatkan posting - -- wordpress get current post id wordpress mendapatkan posting sekarang - -- wordpress $post->ID wordpress $ post-> ID - -- wordpress current page id halaman wordpress id - -- wordpress get id wordpress mendapatkan id - -- post id posting - -- wordpress current post id wordpress posting sekarang - -- get page id wordpress Halaman mendapatkan id wordpress - -- wordpress get the post ID wordpress mendapatkan pos ID - -- wordpress get id of current page wordpress mendapatkan id dari halaman - -- wp post id wp posting - -- $post->id wordpress $ post-> id wordpress - -- $post->ID 104 wordpress $ post-> ID 104 wordpress - -- get current page id wordpress mendapatkan halaman id wordpress - -- get current post id wordpress mendapatkan posting sekarang wordpress - -- wordpress id post id wordpress post - -- wordpress id wordpress id - -- wordpress page id Halaman wordpress id - -- wordpress get current page wordpress mendapatkan halaman ini - -- post->ID post-> ID - -- wordpress post id outside loop wordpress posting di luar loop - -- wordpress global post wordpress pos global - -- get post id outside loop bisa posting di luar loop - -- wordpress current post wordpress saat ini post - -- wordpress get current post wordpress mendapatkan posting sekarang - -- wordpress get post by id wordpress bisa dikirim oleh id - -- post ID in wordpress ID posting di wordpress - -- wordpress get page by id wordpress halaman mendapatkan oleh id - -- wordpress post- id wordpress pasca-id - -- wordpress get id post id wordpress mendapatkan posting - -- wordpress postid wordpress postid - -- how to get page id in wordpress cara mendapatkan id halaman di wordpress - -- wordpress get tags outside loop wordpress mendapatkan tag di luar loop - -- page id wordpress id halaman wordpress - -- wordpress get post id outside loop wordpress bisa posting di luar loop - -- wordpress find post id wordpress menemukan posting - -- wordpress get current id wordpress mendapatkan id saat - -- wordpress page id variable halaman wordpress id variabel - -- current post wordpress post saat ini wordpress - -- wordpress post id number posting wordpress nomor - -- get wordpress post ID mendapatkan post wordpress ID - -- post_id wordpress post_id wordpress - -- post id outside loop posting di luar loop - --