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é.


27 Responses to “Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable” 27 Reakcie na "Načítanie a Brať WordPress pošty ID Mimo Loop ako PHP premenné"

Pages: [2] Stránky: [2] 1 1 » » Show All Zobraziť všetky

  1. Konisto Konisto
    November 7th, 2009 03:41 7.listopadu 2009 03:41
    27 27

    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

  2. Blake Blake
    October 30th, 2009 02:22 30.říjen 2009 02:22
    26 26

    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!

Pages: [2] Stránky: [2] 1 1 » » Show All Zobraziť všetky

Leave a Reply 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> Môžete použiť tieto značky: href = "" <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime = ""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. Prihlásiť sa k pripomienkam funkcia bola zakázaná. To receive notification of latest comments posted, subscribe to Ak chcete dostávať oznámenia o najnovšie komentáre vyslaný, prihláste sa My Digital Life Comments RSS feed Má Digital Life Komentáre RSS or alebo register to receive zaregistrovať na new comments in daily email digest. nové komentáre v dennom email Digest.
Custom Search

New Articles Nové články

Incoming Search Terms for the Article Vcházející Hľadať Čas do člen určitý Artikel

wordpress get post id wordpress získať post id - -- wordpress post id wordpress post id - -- wordpress get page id wordpress dostať stránku id - -- post id wordpress post id wordpress - -- $post->ID $ Post-> ID - -- wordpress get current page id wordpress získať aktuálnej stránke id - -- get post id wordpress získať post id wordpress - -- get post id získať post id - -- wordpress get current post id wordpress získať aktuálne post id - -- wordpress $post->ID wordpress $ post-> ID - -- wordpress current page id wordpress aktuálnej stránke id - -- wordpress get id wordpress dostať id - -- post id post id - -- wordpress current post id wordpress súčasný post id - -- get page id wordpress dostať stránku id wordpress - -- wordpress get the post ID wordpress získať post ID - -- wordpress get id of current page wordpress dostať id aktuálnej stránky - -- wp post id wp post id - -- $post->id wordpress $ Post-> id wordpress - -- $post->ID 104 wordpress $ Post-> ID 104 wordpress - -- get current page id wordpress získať aktuálnej stránke id wordpress - -- get current post id wordpress získať aktuálne post id wordpress - -- wordpress id post wordpress post id - -- wordpress id wordpress id - -- wordpress page id wordpress stránku id - -- wordpress get current page wordpress získať aktuálnej stránky - -- post->ID post-> ID - -- wordpress post id outside loop wordpress post id mimo slučku - -- wordpress global post Wordpress Global post - -- get post id outside loop získať post id mimo slučku - -- wordpress current post wordpress súčasný post - -- wordpress get current post wordpress získať aktuálne post - -- wordpress get post by id wordpress získať príspevok od id - -- post ID in wordpress ID príspevku na wordpress - -- wordpress get page by id wordpress dostať stránku id - -- wordpress post- id wordpress post-id - -- wordpress get id post wordpress získať post id - -- wordpress postid wordpress ID príspevku - -- how to get page id in wordpress ako sa dostať na stránku id wordpress - -- wordpress get tags outside loop wordpress dostať mimo slučku značky - -- page id wordpress Stránka id wordpress - -- wordpress get post id outside loop wordpress post id dostať mimo slučku - -- wordpress find post id wordpress nájsť post id - -- wordpress get current id wordpress získať aktuálne id - -- wordpress page id variable wordpress stránku id variabilný - -- current post wordpress súčasný post wordpress - -- wordpress post id number wordpress post id číslo - -- get wordpress post ID si wordpress post ID - -- post_id wordpress post_id wordpress - -- post id outside loop post id mimo slučku - --