Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable לאחזר קבל וורדפרס פוסט מזהה בחוץ את הלולאה כמו PHP של המשתנה
In WordPress, each post has unique anchor identifier in the form of numeric post ID. ב-WordPress, כל העברת עוגן יש מזהה ייחודי בצורת העברת מספרי הזהות. 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. כאשר בתוך לולאה, שבה וורדפרס תהליכים ומציג את כל ההודעות יוצג בדף הנוכחי וגם מעצבת אותם על פי קריטריונים כיצד הם תואמים שצוין בתוך התגים Loop, תבנית תג the_ID ניתן להשתמש כדי להציג בקלות מזהה את התגובות של בתוך פירסום. Alternatively, inside the the_content filter, declare $id global and use $id to retrieve the post ID. לחילופין, בתוך לסנן את the_content, להכריז $ מזהה גלובלי $ id להשתמש כדי לאחזר את ההודעה מזהה.
the_ID template tag can be used in the following format: the_ID התבנית התג ניתן להשתמש בפורמט הבא:
<?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. לולאה מחוץ או מתוך ההקשר של הפוסט, כמו בכותרת של התחתונה ואפילו באזור הצדדי של תבניות של הבלוג של WordPress, the_ID () לא ניתן להשתמש כפונקציה. 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). במקום, העברת $-> מזהה ישמש להחזיר את העברת מזהה (בתחביר ניתן גם להשתמש בתוך הלולאה שלאחר באמצעות הכרזה $ לכתוב כמו הגלובלי). $post is a global object that holds various information about the posts displayed on the page. העברת $ הוא אובייקט גלובלי המכיל מידע שונים על הודעות מוצגת בדף. So $post->ID will return the post ID of the post. כך שלאחר $> מזהה תחזיר את תעודת הזהות של פירסום ההודעה. It the $post is used inside a function, the $post has to be declared as a global variable. זה $ העברת משמש בתוך פונקציה, שלאחר $ צריך להיות הכריז כמשתנה גלובלי. For example: לדוגמה:
// Works inside of the Loop
function function_name() {
global $post;
$thePostID = $post->ID;
}
or: או:
// 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 ניתן לקרוא ישירות מחוץ למעגל מדי בהודעה אחת התבנית, כגון <? php echo $ post-> מזהה?> יודפס להציג את התגובות של מספר תעודת הזהות.
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. בהודעות מרובות להציג דף, כגון דף אינדקס או דף ארכיון, זה ניתן לאחזר את מקבל את ההודעה האחרונה או המוקדם מזהה את כל ההודעות של המוצג בדף באמצעות פסוקית ORDER BY סדר הודעות לפי תאריך, ולאחר מכן הגדר מספר שיא גבול 1.
Just for example, and there are various way to use the query: רק לדוגמה, ויש דרך שונים כדי להשתמש בשאילתה:
//Get the latest post ID number / / קבל את ההודעה האחרונה מספר מזהה
$post->ID ORDER BY post_date ASC LIMIT 1 $ post-> ID ORDER BY post_date ASC LIMIT 1
//Get the earliest post ID number / / קבל את העברת המוקדם מספר מזהה
$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. חשוב: הדף מכונת תירגם מתפרסם "כמות שהוא" ללא אחריות. Machine translation may be difficult to understand. תרגום מכונה יכול להיות קשה להבין. Please refer to נא עיין original English article המאמר המקורי באנגלית whenever possible. בכל הזדמנות אפשרית.
Related Articles מאמרים קשורים
- Paginating or Split WordPress Post or Page with NextPage in WordPress Not Working Paginating או פיצול וורדפרס פוסט או עמוד עם NextPage ב-WordPress לא תקין
- Disable and Turn Off Post Revisions Tracking in WordPress 2.6 or Above השבת ולכבות מהדורות פוסט מעקב ב-WordPress 2.6 ומעלה
- How to Delete Existing WordPress Post Revisions Stored/Saved כיצד למחוק קיימות מהדורות פוסט וורדפרס המאוחסנים / שמורים
- How To Store Every Post Revisions on Each Auto-Save in WordPress with Limit on Versions Count כיצד לשמור על כל מהדורות אוטומטית כל הודעה שמור ב-WordPress עם הגבלה על גרסאות הרוזן
- Adding Extra More Fields to WordPress Write/Edit Post/Page Right Column הוספת תוספת שדות נוסף על WordPress כתוב / עריכת פוסט / דף העכבר טור
- How to Change the Frequency or Interval WordPress Auto Saves An Editing Post or Page כיצד לשנות את תדירות או מרווח וורדפרס אוטומטי חוסך עריכת פוסט או עמוד
- How to Wrap AdSense Ads Around and Inline Beside Blogger Post Content כיצד מודעות של AdSense עטפו מסביב מיושר לצד Blogger פרסם תוכן
- Move Blogger Inline Ads Between Posts to Inside Within Post Position העבר Blogger בשורה מודעות בין הודעות בתוך תוך כדי פוסט מיקום
- Place AdSense Ad Unit In Various Positions Inside Within Blogger Post Contents במקום יחידת מודעה של AdSense במיקומים שונים בתוך בתוך Blogger פרסם תוכן
- How to Display Elements (Ads) Only On (Or Only Not At) Individual Single Post Item View כיצד רכיבי תצוגה (מודעות) רק (או רק לא) וילה בודדת פרסם הצג פריט










































November 7th, 2009 03:41 7 נובמבר 2009 03:41
Hi, הי,
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. אני מנסה לשנות העברת אישית-new.php באזור admin ו צריכים לגשת post_id פוסט כי אני כרגע העריכה כי טרם פורסם. Any idea how I could do that? יש לך מושג איך אני יכול לעשות את זה?
Thanks תודה
October 30th, 2009 02:22 30 אוקטובר 2009 02:22
Thanks, this was super-helpful and easy to understand! תודה, זה היה סופר מועיל קל להבין! I love code samples! אני אוהב דוגמאות קוד!