Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable Načítanie a Brať WordPress pošty ID Outside Loop ako PHP premenné
In WordPress, each post has unique anchor identifier in the form of numeric post ID. V WordPress, každé miesto má jedinečný identifikátor kotvu vo forme číselnej ID príspevku. 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. Keď vnútri slučky, kde WordPress procesy a zobrazuje každé z miest, ktoré majú byť zobrazená na aktuálnej stránke a formáty je podľa toho, ako zápas uvedených kritérií v rámci značky Loop, šablóny tag the_ID možno ľahko zobraziť miesto na ID vnútri post. Alternatively, inside the the_content filter, declare $id global and use $id to retrieve the post ID. Prípadne, vnútri the_content filter vyhlásiť, $ id globálne a používať $ id získať po ID.
the_ID template tag can be used in the following format: the_ID šablóny značka môže byť použitá v nasledujúcom formáte:
<?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. Mimo Loop alebo z kontextu miesta, napríklad v hlavičky a päty dokonca sidebar oblasti šablóny blogu je WordPress, the_ID () nemôžu byť použité ako funkcia. 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). Miesto toho, $ post-> ID bude použitý na návrat na miesto ID (syntaxu môže byť použitý vnútri slučky na post vyhlásením, $ post ako globálny). $post is a global object that holds various information about the posts displayed on the page. $ Post je globálny objekt, ktorý má rôzne informácie o pracovných miest zobrazených na stránke. So $post->ID will return the post ID of the post. Takže $ post-> ID vráti post ID post. It the $post is used inside a function, the $post has to be declared as a global variable. To $ post je použitý vnútri funkcie, $ post musia byť deklarovaný ako globálne premenné. For example: Napríklad:
// Works inside of the Loop
function function_name() {
global $post;
$thePostID = $post->ID;
}
or: alebo:
// 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 možné vyvolať priamo mimo Loop príliš v jediné miesto šablóny, ako <? Php echo $ post-> ID?> Bude tlačiť zobrazí miesto ID číslo.
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. Vo viac príspevkov zobrazenie stránky, ako je index stránke alebo archívne stránky, je možné získať získať najnovšie alebo najstaršie ID príspevku zo všetkých miest zobrazených na stránke pomocou klauzule ORDER BY objednať príspevky od dátumu, a potom nastavte Počet záznamov na LIMIT 1.
Just for example, and there are various way to use the query: Len pre príklad, a tam sú rôzne spôsob, ako používať dotazu:
//Get the latest post ID number / / Get the latest post ID číslo
$post->ID ORDER BY post_date ASC LIMIT 1 $ Post-> ID ORDER BY post_date ASC LIMIT 1
//Get the earliest post ID number / / Get najskôr po ID číslo
$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. Upozornenie: stránka je stroje preložené a za predpokladu, "ako je" bez záruky. Machine translation may be difficult to understand. Strojový preklad môže byť ťažké pochopiť. Please refer to Nájdete na original English article originál Anglicky artikl whenever possible. ak je to možné.
Related Articles Súvisiace články
- Paginating or Split WordPress Post or Page with NextPage in WordPress Not Working Paginating alebo Split WordPress Post alebo stránky s NextPage do WordPress Nie Činnosť
- Disable and Turn Off Post Revisions Tracking in WordPress 2.6 or Above Oslabiť a Zastavenie toku po Revízia Monitorovanie do WordPress 2.6 či Nad
- How to Delete Existing WordPress Post Revisions Stored/Saved Ako odstrániť existujúce WordPress pošty Revízia Uložené / Uložené
- How To Store Every Post Revisions on Each Auto-Save in WordPress with Limit on Versions Count Ako uchovávať dobré mravy revízie na každý Auto-Uložiť do WordPress s Hranica ďalej Líčenie Počet
- Adding Extra More Fields to WordPress Write/Edit Post/Page Right Column Pridanie Extra Ďalšie odbory na WordPress Write / Upraviť Posta / Blok Pravý stĺpec
- How to Change the Frequency or Interval WordPress Auto Saves An Editing Post or Page Ako meniť frekvenciu alebo Interval WordPress Auto Šetrí Úprava pošty alebo Page
- How to Wrap AdSense Ads Around and Inline Beside Blogger Post Content Ako sa obalí AdSense Reklamy Asi a Inline U Blogger pošty Obsah
- Move Blogger Inline Ads Between Posts to Inside Within Post Position Presunúť Blogger Inline Reklamy Medzi Pracovné miesta Inside Do pošty Pozícia
- Place AdSense Ad Unit In Various Positions Inside Within Blogger Post Contents Miesto AdSense reklamné jednotky na rôznych pozíciách v rámci Vnútri Blogger pošty Obsah
- How to Display Elements (Ads) Only On (Or Only Not At) Individual Single Post Item View Ako na zobrazenie prvkov (reklamy) len (alebo len vôbec nie) Jednotlivé položky jediný príspevok Zobraziť










































November 7th, 2009 03:41 7.listopadu 2009 03:41
Hi, Nazdar,
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. Snažím sa zmeniť vlastné post-new.php v admin sekcii a potrebujú prístup post_id o príspevok, ktorý som editorom, a že doteraz nebola zverejnená. Any idea how I could do that? Potuchy, ako by som mohol urobiť?
Thanks Vďaka
October 30th, 2009 02:22 30.říjen 2009 02:22
Thanks, this was super-helpful and easy to understand! Vďaka, to bolo super-užitočné a zrozumiteľné! I love code samples! Milujem ukážky kódu!