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. בכל הזדמנות אפשרית.


27 Responses to “Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable” 27 תגובות ל "לאחזר קבל וורדפרס פוסט מזהה בחוץ את הלולאה כמו PHP של המשתנה"

Pages: [2] עמודים: [2] 1 1 » » Show All הצג הכל

  1. Konisto Konisto
    November 7th, 2009 03:41 7 נובמבר 2009 03:41
    27 27

    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 תודה

  2. Blake בלייק
    October 30th, 2009 02:22 30 אוקטובר 2009 02:22
    26 26

    Thanks, this was super-helpful and easy to understand! תודה, זה היה סופר מועיל קל להבין! I love code samples! אני אוהב דוגמאות קוד!

Pages: [2] עמודים: [2] 1 1 » » Show All הצג הכל

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> באפשרותך להשתמש בתגים אלה: <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. כדי להירשם הערות תכונה הושבת. To receive notification of latest comments posted, subscribe to כדי לקבל הודעה העדכנית של תגובות, כדי להירשם My Digital Life Comments RSS feed החיים שלי דיגיטליות תגובות RSS Feed or או register to receive הרשמה לקבלת new comments in daily email digest. תגובות חדש ב דוא"ל תקציר יומי.
Custom Search

New Articles מאמרים חדשים

Incoming Search Terms for the Article תנאי נכנסות חיפוש עבור מאמרים

wordpress get post id Wordpress לקבל מזהה פוסט - -- wordpress post id פירסום WordPress ID - -- wordpress get page id Wordpress לקבל זיהוי דף - -- $post->ID העברת $-> ID - -- post id wordpress פירסום WordPress ID - -- get post id wordpress לקבל פירסום WordPress ID - -- get post id לקבל פירסום זהות - -- wordpress get current page id Wordpress לקבל העמוד הנוכחי ID - -- wordpress get current post id Wordpress לקבל פירסום הנוכחית ID - -- wordpress $post->ID פירסום-WordPress $> מזהה - -- wordpress get id Wordpress לקבל ID - -- wordpress current page id WordPress הדף הנוכחי ID - -- wordpress current post id WordPress ההודעה הנוכחית ID - -- $post->ID 104 wordpress פירסום-WordPress $> מזהה 104 - -- wordpress get id of current page Wordpress לקבל ID של העמוד הנוכחי - -- get current post id wordpress לקבל פירסום הנוכחית WordPress ID - -- $post->id wordpress פירסום-WordPress $> ID - -- get post id outside loop לקבל פירסום מזהה מחוץ לולאה - -- wordpress current post WordPress ההודעה הנוכחית - -- post id פירסום ID - -- wordpress get current page Wordpress לקבל העמוד הנוכחי - -- wordpress post id outside loop WordPress העברת מזהה מחוץ לולאה - -- wordpress get id post Wordpress לקבל פירסום זהות - -- wordpress postid WordPress postid - -- get page id wordpress לקבל WordPress דף ID - -- wordpress id post WordPress פירסום זהות - -- wordpress id WordPress ID - -- wordpress get current post Wordpress לקבל פירסום הנוכחי - -- wordpress get the post ID Wordpress לקבל את ההודעה מזהה - -- wordpress get post id outside loop Wordpress לקבל פירסום מזהה מחוץ לולאה - -- wordpress page id variable דף WordPress ID משתנה - -- post->ID פירסום-> ID - -- post- id wordpress פירסום ID-WordPress - -- wordpress php post ID פירסום PHP WordPress מזהה - -- wordpress global post WordPress פירסום הגלובלי - -- how to get page id in wordpress איך להגיע לדף מזהה ב-WordPress - -- wordpress latest post id WordPress בהודעה האחרונה ID - -- wordpress get post by id Wordpress לקבל הודעה על ידי ID - -- get post category wordpress לקבל WordPress קטגוריה פירסום - -- get current page id wordpress Wordpress לקבל העמוד הנוכחי ID - -- wordpress post date outside loop תאריך פירסום WordPress מחוץ לולאה - -- wordpress find post id WordPress מצא קוד זיהוי פירסום - -- how to get id php wordpress איך להגיע WordPress PHP מזהה - -- how to get a post id in wordpress in page.php איך לקבל העברת מזהה WordPress על page.php - -- wordpress get page by id Wordpress לקבל דף על ידי ID - -- get wordpress post ID לקבל פירסום WordPress מזהה - -- get id wordpress לקבל ID WordPress - -- post_id wordpress WordPress post_id - -- post id outside loop העברת מזהה לולאה בחוץ - -- post info outside loop העברת מידע מחוץ לולאה - --