Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable Priimti ir gauti WordPress Rašyti ID Ne, PHP Rodiklis Loop
In WordPress, each post has unique anchor identifier in the form of numeric post ID. Į WordPress, kiekvienas postas turi unikalią žymę identifikatorių skaitmeniniai post forma 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. Kai viduje Ciklas, kai WordPress procesų ir rodo kiekvienos pareigybės, kurios bus rodomi šiame puslapyje ir formatai juos pagal tai, kaip jie atitinka tam tikrus kriterijus, per Loop žymeles Žymos the_ID galima lengvai parodyti Post ID viduje paštu. Alternatively, inside the the_content filter, declare $id global and use $id to retrieve the post ID. Arba viduje the_content filtras, paskelbti $ Id pasaulio ir naudoti $ Id gauti po ID.
the_ID template tag can be used in the following format: the_ID Žymos gali būti naudojamos tokios formos:
<?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. Už Ciklas arba iš posto kontekste pavyzdžiui, antraštę apačią ir net Sidebar plotas šablonų WordPress dienoraštį, the_ID () negali būti naudojamas kaip funkcija. 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). Vietoj to, $ post-> ID bus naudojamas grįžti paštu ID (sintaksė gali būti naudojamas ir viduje, pareikšdamas, $ post, Pasaulinė pašto loop). $post is a global object that holds various information about the posts displayed on the page. $ postas pasaulio objektas, turintis įvairios informacijos apie pranešimų rodomas puslapyje. So $post->ID will return the post ID of the post. Taigi $ post-> ID grįš paštu ID paštu. It the $post is used inside a function, the $post has to be declared as a global variable. Ji $ postas viduje naudojamos funkcijos, $ paštu, turi būti deklaruojamos kaip globalinis kintamasis. For example: Pavyzdžiui
// Works inside of the Loop
function function_name() {
global $post;
$thePostID = $post->ID;
}
or: arba:
// 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, gali būti vadinamas tiesiai už Loop pernelyg į vieną žinutės šabloną, pavyzdžiui, <? php echo $ post-> ID?> bus atspausdinti ekrane Post numerį.
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. Į keletą postų mano puslapyje pvz tituliniame puslapyje ir archyvo puslapyje, kad įmanoma gauti Gaukite naujausią ar anksčiau po ID visi Žinutės puslapyje rodomi naudojant ORDER BY užsisakyti pagal datą žinutes, tada nustatykite įrašo numeris LIMIT 1.
Just for example, and there are various way to use the query: Tiesiog, pavyzdžiui, ir yra įvairių būdų naudoti užklausą:
//Get the latest post ID number / / Get the latest post ID numerį
$post->ID ORDER BY post_date ASC LIMIT 1 $ post-> ID ORDER BY post_date ASC LIMIT 1
//Get the earliest post ID number / / Gauti anksčiausiai po ID numerį
$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. DĖMESIO: Šis puslapis yra mašina išvertė ir pateikiama "kaip yra" be garantijų. Machine translation may be difficult to understand. Automatinis vertimas gali būti sunku suprasti. Please refer to Remkitės original English article originalas anglų straipsnis whenever possible. jei įmanoma.
Related Articles Susiję straipsniai
- Paginating or Split WordPress Post or Page with NextPage in WordPress Not Working Kiekių arba neskaldytos WordPress Siųsti puslapį arba su Nextpage į WordPress neveikia
- Disable and Turn Off Post Revisions Tracking in WordPress 2.6 or Above Išjungti ir išjungti Rašyti Atnaujinimai stebėjimas Wordpress 2.6 ar aukščiau
- How to Delete Existing WordPress Post Revisions Stored/Saved Kaip pašalinti esamus WordPress Rašyti Atnaujinimai Išsaugota / Išsaugota
- How To Store Every Post Revisions on Each Auto-Save in WordPress with Limit on Versions Count Kaip laikyti bet post patikslinimai Kiekviena Auto-Išskyrus WordPress su limitas versijas Count
- Adding Extra More Fields to WordPress Write/Edit Post/Page Right Column Įrašyta Ekstra daugiau laukų į WordPress Rašyti / redaguoti Post / Page dešiniosios skilties
- How to Change the Frequency or Interval WordPress Auto Saves An Editing Post or Page Kaip pakeisti dažnį arba intervalas WordPress Auto Sutaupo redagavimas pašto ar Puslapis
- How to Wrap AdSense Ads Around and Inline Beside Blogger Post Content Kaip Wrap Around AdSense reklamos ir linijiniai Be Blogger turinys
- Move Blogger Inline Ads Between Posts to Inside Within Post Position Perkelti "Blogger" Inline reklama tarp pranešimų į vidų per Post Pareigos
- Place AdSense Ad Unit In Various Positions Inside Within Blogger Post Contents Vieta AdSense reklamos vienetas įvairiose padėtyse Viduje Per Blogger Turinys
- How to Display Elements (Ads) Only On (Or Only Not At) Individual Single Post Item View Kaip Rodyti elementai (Skelbimai) tik (ar tik ne) Individuali Single Post Prekė vaizdas










































November 7th, 2009 03:41 7 lapkritis 2009 03:41
Hi, Labas,
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. Bandau pakeisti Custom po new.php administratorius srityje ir turi patekti į pranešimą post_id kad aš dabar redaguoti ir kad iki šiol nebuvo paskelbtas. Any idea how I could do that? Bet kokią idėją, kaip galėčiau tai padaryti?
Thanks Ačiū
October 30th, 2009 02:22 30 spalis 2009 02:22
Thanks, this was super-helpful and easy to understand! Ačiū, tai buvo itin naudingas ir lengvai suprantama! I love code samples! I love kodo pavyzdžius!