Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable निकालें और जाओ WordPress पोस्ट PHP परिवर्तनीय के रूप में लूप के बाहर आईडी
In WordPress, each post has unique anchor identifier in the form of numeric post ID. WordPress में, प्रत्येक पोस्ट न्यूमेरिक पोस्ट के रूप में लंगर अद्वितीय पहचानकर्ता है 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. लूप, जहां WordPress प्रक्रियाओं और पदों में से प्रत्येक के भीतर प्रदर्शित करता है जब उन्हें वे कैसे निर्दिष्ट मैच के मानदंड के अनुसार लूप टैग के भीतर, the_ID टैग टेम्पलेट को आसानी से अंदर है पोस्ट आईडी प्रदर्शन किया जा सकता है वर्तमान पृष्ठ और स्वरूपों को प्रदर्शित पोस्ट. Alternatively, inside the the_content filter, declare $id global and use $id to retrieve the post ID. आईडी वैकल्पिक रूप से, the_content फ़िल्टर के अंदर, वैश्विक आईडी डॉलर और उपयोग करने के बाद पुनः प्राप्त आईडी $ घोषणा.
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. पोस्ट $> आईडी लूप के सीधे बाहर बुलाया जा सकता है भी एक पोस्ट में इस तरह के रूप में टेम्पलेट, <php? $ बाद> आईडी गूंज?> मुद्रित है पोस्ट आईडी नंबर प्रदर्शित करेगा.
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. कई पदों में ऐसे सूचकांक पृष्ठ या संग्रह पृष्ठ के रूप में पृष्ठ को देखने के लिए पुनः प्राप्त करने के लिए नवीनतम या जल्द से जल्द के बाद सब एक आदेश द्वारा खंड का उपयोग करने की तारीख से पदों के आदेश के पृष्ठ पर प्रदर्शित पदों की पहचान, और फिर सेट हो सकता है 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 पोस्ट $> आईडी आदेश ए एस सी सीमा 1 post_date द्वारा
//Get the earliest post ID number / / के बाद जल्द से जल्द जाओ संख्या आईडी
$post->ID ORDER BY post_date DESC LIMIT 1 पोस्ट $> आईडी आदेश desc सीमा 1 post_date द्वारा
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 या भाजित WordPress पोस्ट या पृष्ठ 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 कैसे WordPress पोस्ट संशोधन संग्रहित मौजूदा हटाएँ / सहेजा गया
- 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 कैसे आवृत्ति या अंतराल WordPress ऑटो बचाता एक संपादन पोस्ट या पृष्ठ को बदलें
- How to Wrap AdSense Ads Around and Inline Beside Blogger Post Content और लगभग इनलाइन अलावा ब्लॉगर पोस्ट सामग्री लपेटें ऐडसेंस विज्ञापन कैसे
- Move Blogger Inline Ads Between Posts to Inside Within Post Position ब्लॉगर के बीच इनलाइन विज्ञापन हटो पोस्ट स्थिति के अंदर अंदर से डाक
- Place AdSense Ad Unit In Various Positions Inside Within Blogger Post Contents जगह ऐडसेंस विज्ञापन इकाई के भीतर ब्लॉगर पोस्ट सामग्री के भीतर विभिन्न स्थानों पर
- 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 संशोधित करने की कोशिश कर रहा हूँ और एक के बाद 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! मैं कोड नमूने प्यार करता हूँ!