Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable Lấy và Nhận WordPress Post ID Bên ngoài Loop như PHP Variable

In WordPress, each post has unique anchor identifier in the form of numeric post ID. Trong WordPress, đăng từng có định danh duy nhất neo dưới hình thức đăng số 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. Khi bên trong Vòng, nơi WordPress quy trình và hiển thị mỗi bài viết sẽ được hiển thị trên trang hiện tại và định dạng chúng theo các tiêu chí như thế nào họ phù hợp với quy định trong Các thẻ Vòng, mẫu thẻ the_ID có thể được sử dụng để dễ dàng hiển thị ID của bài bên trong post. Alternatively, inside the the_content filter, declare $id global and use $id to retrieve the post ID. Ngoài ra, bên trong các bộ lọc the_content, tuyên bố $ id toàn cầu và sử dụng $ id để lấy đăng bài ID.

the_ID template tag can be used in the following format: the_ID mẫu thẻ có thể được sử dụng trong các định dạng sau:

<?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. Vòng ngoài hoặc ra khỏi bối cảnh của bài viết, chẳng hạn như trong tiêu đề của chân và thậm chí cả khu vực bên trong các mẫu của blog's, the_ID () không thể được sử dụng như là một hàm. 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). Thay vào đó, đăng $-> ID sẽ được dùng để trả lại bài ID (cú pháp cũng có thể được sử dụng bên trong Loop của post by $ post tuyên bố như trên toàn cầu). $post is a global object that holds various information about the posts displayed on the page. $ post là một đối tượng trên toàn cầu chứa các thông tin khác nhau về các bài viết được hiển thị trên trang. So $post->ID will return the post ID of the post. Vì vậy, $ post-> ID sẽ trả lại bài ID của bài này. It the $post is used inside a function, the $post has to be declared as a global variable. Đăng It của $ được sử dụng trong một hàm, các bài $ đã được khai báo là một biến toàn cầu. For example: Ví dụ:


// Works inside of the Loop
function function_name() {
global $post;
$thePostID = $post->ID;
}

or: hoặc:


// 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 có thể được gọi trực tiếp bên ngoài Loop quá trong một bài đăng đơn mẫu, chẳng hạn như <? php echo $ post-> ID> sẽ in hiển thị số ID của bài?.

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. Trong bài viết nhiều lần xem trang như là trang index hay trang lưu trữ, có thể để lấy được bài mới nhất hoặc sớm nhất ID của tất cả các bài viết hiển thị trên trang bằng cách sử dụng một mệnh đề ORDER BY để đặt hàng các bài viết theo ngày, và sau đó đặt số lượng hồ sơ để LIMIT 1.

Just for example, and there are various way to use the query: Chỉ cần ví dụ, và có nhiều cách để sử dụng các truy vấn:

//Get the latest post ID number / / Get the latest số ID
$post->ID ORDER BY post_date ASC LIMIT 1 $ post-> ID post_date ORDER BY ASC LIMIT 1

//Get the earliest post ID number / / Get the post sớm nhất số ID
$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. Quan trọng: Sửa là máy dịch và cung cấp "như là" không có bảo hành. Machine translation may be difficult to understand. Máy dịch thuật có thể khó hiểu. Please refer to Vui lòng tham khảo original English article bản gốc tiếng Anh bài viết whenever possible. bất cứ khi nào có thể.


27 Responses to “Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable” 27 Responses to "Retrieve và Nhận WordPress Post ID Bên ngoài Loop như PHP Variable"

Pages: [2] Trang: [2] 1 1 » » Show All Hiển thị tất cả

  1. Konisto Konisto
    November 7th, 2009 03:41 07 Tháng 11 2009 03:41
    27 27

    Hi, Chào,

    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. Tôi đang cố gắng để sửa đổi một bài tuỳ-new.php trong lĩnh vực quản trị và cần để truy cập post_id của đăng rằng tôi đang chỉnh sửa và chưa được xuất bản. Any idea how I could do that? Bất cứ ý tưởng làm thế nào tôi có thể làm điều đó?

    Thanks Cảm ơn

  2. Blake Blake
    October 30th, 2009 02:22 Ngày 30 tháng 10 năm 2009 02:22
    26 26

    Thanks, this was super-helpful and easy to understand! Thanks, đây là siêu hữu ích và dễ hiểu! I love code samples! Tôi thích mẫu mã!

Pages: [2] Trang: [2] 1 1 » » Show All Hiển thị tất cả

Leave a Reply Để lại một trả lời

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> Bạn có thể sử dụng các thẻ: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime = ""> <em> <i> <q <strike> <strong>

Subscribe to comments feature has been disabled. Thuê bao với ý kiến đều đã bị vô hiệu hoá. To receive notification of latest comments posted, subscribe to Để nhận được thông báo mới nhất đăng ý kiến, đăng ký với My Digital Life Comments RSS feed My Digital Life kiến RSS feed or hoặc register to receive đăng ký để nhận được new comments in daily email digest. Các ý kiến mới trong email tiêu hàng ngày.
Custom Search

New Articles Bài viết mới

Incoming Search Terms for the Article Tìm đến các Điều khoản Điều

wordpress get post id wordpress lấy id bài viết - -- wordpress post id wordpress đăng id - -- wordpress get page id wordpress nhận id trang - -- post id wordpress đăng wordpress id - -- $post->ID $ post-> ID - -- wordpress get current page id wordpress được trang hiện id - -- get post id wordpress nhận đăng wordpress id - -- get post id nhận đăng id - -- wordpress get current post id wordpress nhận đăng hiện id - -- wordpress $post->ID wordpress $ post-> ID - -- wordpress current page id wordpress hiện tại trang id - -- wordpress get id wordpress nhận id - -- post id đăng id - -- wordpress current post id wordpress đăng bài hiện tại id - -- get page id wordpress nhận wordpress trang id - -- wordpress get the post ID wordpress có được đăng ID - -- wordpress get id of current page wordpress nhận id của trang hiện tại - -- wp post id wp đăng id - -- $post->id wordpress $ post-> id wordpress - -- $post->ID 104 wordpress $ post-> ID 104 wordpress - -- get current page id wordpress nhận được hiện tại trang id wordpress - -- get current post id wordpress được đăng bài hiện tại id wordpress - -- wordpress id post wordpress đăng id - -- wordpress id wordpress id - -- wordpress page id wordpress trang id - -- wordpress get current page wordpress được trang hiện tại - -- post->ID post-> ID - -- wordpress post id outside loop wordpress đăng id bên ngoài vòng lặp - -- wordpress global post wordpress đăng toàn cầu - -- get post id outside loop nhận đăng id bên ngoài vòng lặp - -- wordpress current post wordpress đăng bài hiện tại - -- wordpress get current post wordpress nhận đăng hiện tại - -- wordpress get post by id wordpress nhận post by id - -- post ID in wordpress post ID trong wordpress - -- wordpress get page by id wordpress được trang theo id - -- wordpress post- id wordpress post-id - -- wordpress get id post wordpress nhận đăng id - -- wordpress postid wordpress postid - -- how to get page id in wordpress làm thế nào để có được trang id trong wordpress - -- wordpress get tags outside loop wordpress nhận thẻ bên ngoài vòng lặp - -- page id wordpress Sửa id wordpress - -- wordpress get post id outside loop wordpress nhận đăng id bên ngoài vòng lặp - -- wordpress find post id wordpress tìm id bài viết - -- wordpress get current id wordpress nhận id hiện tại - -- wordpress page id variable wordpress trang id biến - -- current post wordpress hiện đăng wordpress - -- wordpress post id number wordpress đăng số id - -- get wordpress post ID nhận đăng wordpress ID - -- post_id wordpress post_id wordpress - -- post id outside loop đăng id vòng ngoài - --