Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable Iegūt un saņemt WordPress Post ID Ārpus kā PHP Mainīgs Loop

In WordPress, each post has unique anchor identifier in the form of numeric post ID. WordPress, katram amatam ir unikāla enkuru identifikatoru, kā ciparu post 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. Kad iekšā Loop, kur WordPress procesiem un parāda katra amatu izvieto uz pašreizējo lappusi un formāti tos saskaņā ar to, kā tie atbilst noteiktiem kritērijiem, kas Loop tagus, template tag the_ID var izmantot, lai viegli parādīt Post ID iekšpusē post. Alternatively, inside the the_content filter, declare $id global and use $id to retrieve the post ID. Alternatīvi, iekšpusē the_content filtrs, atzīt $ id pasaules un izmantot $ id, lai iegūtu pēc ID.

the_ID template tag can be used in the following format: the_ID template tag var izmantot šādā formātā:

<?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. Ārpus Loop vai no konteksta un pēc, piemēram, galvenes un kājenes un pat Sidebar platība šabloni WordPress blogā, the_ID () nevar izmantot kā funkciju. 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). Tā vietā, $ post-> ID tiks izmantots, lai atgrieztos pēc ID (sintakse var izmantot arī iekšpusē cilpas post pasludinot $ amatu pasaulē). $post is a global object that holds various information about the posts displayed on the page. $ post ir pasaules mēroga objekts, kas pieder dažādu informāciju par amatu redzams lapā. So $post->ID will return the post ID of the post. Tik $ post-> ID atgriezīsies pēc ID post. It the $post is used inside a function, the $post has to be declared as a global variable. Tā $ pastu iekšpusē lietoto funkciju, $ post ir jādeklarē kā globālo mainīgo. For example: For example:


// Works inside of the Loop
function function_name() {
global $post;
$thePostID = $post->ID;
}

or: vai:


// 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 var saukt tieši ārpus Loop arī ir viens post veidni, piemēram, <? php echo $ post-> ID?> izdrukās displejs Post numuru.

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. Ar vairākiem amatiem Skatīt lapas, piemēram, ar indeksu lapa vai arhīva lapā, ir iespējams iegūt iegūt jaunāko vai drīz pēc ID visiem amatiem parādīts lapā, izmantojot ORDER BY klauzula pasūtīt pēc datuma amatos, un pēc tam iestatiet ieraksta numuru 1 limitu.

Just for example, and there are various way to use the query: Tikai piemērs, un ir dažādi, kā izmantot vaicājumu:

//Get the latest post ID number / / Get latest post ID numurs
$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 ātrāk raksta ID numuru
$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. SVARĪGI: lapa mašīna iztulkot un pasniegts tàds, "kàds tas ir" bez garantijas. Machine translation may be difficult to understand. Mašīntulkošanas var būt grūti saprast. Please refer to Lūdzu, skatiet original English article oriģināls angļu rakstu whenever possible. kad vien iespējams.


27 Responses to “Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable” 27 Atbildes uz "Retrieve un saņemt WordPress Post ID Ārpus kā PHP Mainīgs Loop"

Pages: [2] Lapas: [2] 1 1 » » Show All Parādīt visus

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

    Hi, Čau,

    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. Es cenšos mainīt pasūtījuma pēc new.php in admin jomā un nepieciešama piekļuve post_id no amata, ka es esmu patlaban rediģē, un ka vēl nav publicēts. Any idea how I could do that? Jebkura doma, kā es varētu darīt?

    Thanks Pateicība

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

    Thanks, this was super-helpful and easy to understand! Paldies, tas bija super, noderīgu un viegli saprotams! I love code samples! I love kodu paraugus!

Pages: [2] Lapas: [2] 1 1 » » Show All Parādīt 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> Jūs varat izmantot šos tagus: <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. Parakstīties uz komentāriem iezīme ir atspējota. To receive notification of latest comments posted, subscribe to Saņemt informāciju par jaunāko komentārus, parakstīties uz My Digital Life Comments RSS feed Mana Digital Life Comments RSS feed or vai register to receive reģistrēties, lai saņemtu new comments in daily email digest. jauni komentāri ikdienas e-pasta sagremot.
Custom Search

New Articles Jauns pants

Incoming Search Terms for the Article Ienākošo Meklēt noteikumi pants

wordpress get post id WordPress get post id - -- wordpress post id WordPress post id - -- wordpress get page id WordPress get page id - -- $post->ID $ post-> ID - -- post id wordpress post id WordPress - -- get post id wordpress get post id WordPress - -- get post id get post id - -- wordpress get current page id WordPress get current page id - -- wordpress get current post id WordPress iegūt pašreizējo amatu id - -- wordpress $post->ID WordPress $ post-> ID - -- wordpress get id WordPress get id - -- wordpress current page id WordPress pašreizējo lapu id - -- wordpress current post id WordPress pašreizējais post id - -- $post->ID 104 wordpress $ post-> ID 104 WordPress - -- wordpress get id of current page WordPress get id esošās lapas - -- get current post id wordpress get pašreizējais post id WordPress - -- $post->id wordpress $ post-> ID wordpress - -- get post id outside loop get post id ārpus cilpa - -- wordpress current post WordPress pašreizējais post - -- post id post id - -- wordpress get current page WordPress get current page - -- wordpress post id outside loop WordPress post id ārpus cilpa - -- wordpress get id post WordPress get id pastu - -- wordpress postid WordPress postid - -- get page id wordpress get page id WordPress - -- wordpress id post WordPress id post - -- wordpress id WordPress id - -- wordpress get current post WordPress iegūt pašreizējo amatu - -- wordpress get the post ID WordPress iegūt pēc ID - -- wordpress get post id outside loop WordPress get post id ārpus cilpa - -- wordpress page id variable WordPress page id mainīgo - -- post->ID post-> ID - -- post- id wordpress post-ID wordpress - -- wordpress php post ID wordpress php raksta ID - -- wordpress global post WordPress pasaulē post - -- how to get page id in wordpress kā nokļūt lapā id in WordPress - -- wordpress latest post id WordPress latest post id - -- wordpress get post by id WordPress get pastu pēc ID - -- get post category wordpress get post kategorijā WordPress - -- get current page id wordpress get current page id WordPress - -- wordpress post date outside loop WordPress post datums ārpus cilpa - -- wordpress find post id WordPress atrast pēc id - -- how to get id php wordpress kā iegūt id php WordPress - -- how to get a post id in wordpress in page.php kā iegūt pēc ID WordPress page.php - -- wordpress get page by id WordPress nokļūt lapā, id - -- get wordpress post ID get WordPress pēc ID - -- get id wordpress get id WordPress - -- post_id wordpress post_id WordPress - -- post id outside loop post id ārpus cilpa - -- post info outside loop Post Info ārpus cilpa - --