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.


27 Responses to “Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable” 27 Responses to "Priimti ir gauti WordPress Rašyti ID Ne, PHP Rodiklis Ciklas"

Pages: [2] Puslapiai: [2] 1 1 » » Show All Rodyti visus

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

    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ū

  2. Blake Blake
    October 30th, 2009 02:22 30 spalis 2009 02:22
    26 26

    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!

Pages: [2] Puslapiai: [2] 1 1 » » Show All Rodyti visus

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> Galite naudoti šiuos žodžius: <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. Subscribe to comments funkcija buvo išjungta. To receive notification of latest comments posted, subscribe to Norėdami gauti pranešimus apie naujausius komentarų, užsiprenumeruoti My Digital Life Comments RSS feed Mano skaitmeninis gyvenimas Komentarų RSS or arba register to receive Registruokitės gauti new comments in daily email digest. Nauji komentarai kasdien elektroniniu paštu.
Custom Search

New Articles Nauji straipsniai

Incoming Search Terms for the Article Gaunamus paieškos terminus straipsnis

wordpress get post id WordPress gauti pranešimą ID - -- wordpress post id WordPress post id - -- wordpress get page id Wordpress get page id - -- $post->ID $ post-> ID - -- post id wordpress paštu ID WordPress - -- get post id wordpress Get post id WordPress - -- get post id Get post id - -- wordpress get current page id WordPress gauti dabartinio puslapio numeris - -- wordpress get current post id WordPress gauti dabartinis post id - -- wordpress $post->ID WordPress $ post-> ID - -- wordpress get id WordPress gauti ID - -- wordpress current page id WordPress dabartinio puslapio numeris - -- wordpress current post id WordPress dabartinis post id - -- $post->ID 104 wordpress $ post-> ID 104 WordPress - -- wordpress get id of current page Wordpress get id šiame puslapyje - -- get current post id wordpress Gauti dabartinis post id WordPress - -- $post->id wordpress $ post-> ID WordPress - -- get post id outside loop Get post id už kilpos - -- wordpress current post WordPress paskelbimą - -- post id paštu ID - -- wordpress get current page WordPress gauti šiame puslapyje - -- wordpress post id outside loop WordPress post id už kilpos - -- wordpress get id post Wordpress get ID paštu - -- wordpress postid WordPress postid - -- get page id wordpress get page id WordPress - -- wordpress id post WordPress ID paštu - -- wordpress id WordPress ID - -- wordpress get current post WordPress gauti dabartinis paštu - -- wordpress get the post ID WordPress gauti pranešimą ID - -- wordpress get post id outside loop WordPress Get post id išorės kontūro - -- wordpress page id variable WordPress page id kintamąjį - -- post->ID post-> ID - -- post- id wordpress post-id WordPress - -- wordpress php post ID WordPress PHP paštu ID - -- wordpress global post WordPress globalinis paštu - -- how to get page id in wordpress kaip gauti puslapis ID WordPress - -- wordpress latest post id WordPress latest post id - -- wordpress get post by id WordPress paštu gauti pagal ID - -- get post category wordpress Get post kategoriją WordPress - -- get current page id wordpress Gauti dabartinio puslapio numeris WordPress - -- wordpress post date outside loop WordPress Post Date už kilpos - -- wordpress find post id WordPress rasti post id - -- how to get id php wordpress kaip gauti ID PHP WordPress - -- how to get a post id in wordpress in page.php kaip gauti paštu ID WordPress į page.php - -- wordpress get page by id Wordpress get puslapio ID - -- get wordpress post ID Get WordPress paštu ID - -- get id wordpress Gauk ID WordPress - -- post_id wordpress post_id WordPress - -- post id outside loop paštu ID išorės kontūro - -- post info outside loop Post Info už kilpos - --