Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable Recuperare e arrivare WordPress post id al di fuori del loop come variabile php

In WordPress, each post has unique anchor identifier in the form of numeric post ID. In WordPress, ogni post ha identificatore unico ancoraggio in forma di post ID numerico. 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. Quando all'interno del Loop, dove WordPress processi e visualizza ciascuno dei posti a essere visualizzati nella pagina corrente e formati in base al loro modo che corrispondano ai criteri specificati il loop tag, etichetta the_ID modello può essere utilizzato per visualizzare facilmente il posto ID all'interno del post. Alternatively, inside the the_content filter, declare $id global and use $id to retrieve the post ID. In alternativa, the_content all'interno del filtro, dichiarare $ id globale e di uso $ id per recuperare il posto ID.

the_ID template tag can be used in the following format: the_ID tag modello può essere utilizzato nel seguente formato:

<?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. Al di fuori del loop o fuori dal contesto del post, ad esempio in intestazione e piè di pagina della barra laterale, anche nel settore dei modelli di WordPress blog, the_ID () non può essere utilizzato come una funzione. 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). Invece, $ post-> ID verrà utilizzato per riprendere il posto ID (la sintassi può anche essere utilizzato all'interno del Loop del posto dichiarando $ post come globale). $post is a global object that holds various information about the posts displayed on the page. $ post è un oggetto globale che contiene varie informazioni sul post visualizzati nella pagina. So $post->ID will return the post ID of the post. Così $ post-> ID restituirà il posto ID del post. It the $post is used inside a function, the $post has to be declared as a global variable. E 'il $ post è utilizzato all'interno di una funzione, il $ post deve essere dichiarata come variabile globale. For example: Per esempio:


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

or: oppure:


// Works in single post outside of the Loop / / Works in unico posto al di fuori del Loop
function function_name() { funzione function_name () (
global $wp_query; global $ wp_query;
$thePostID = $wp_query->post->ID; 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 può essere chiamato direttamente al di fuori del Loop troppo in un unico modello post, come ad esempio <? php echo $ post-> ID?> stamperà la visualizzazione della Posta numero ID.

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. In più posti di visualizzare la pagina come pagina indice o pagina archivio, è possibile recuperare il ottenere la versione più recente prima o dopo ID di tutti i post visualizzati nella pagina utilizzando una clausola ORDER BY per ordinare i messaggi di data, e quindi impostare il numero di record di limitare 1.

Just for example, and there are various way to use the query: Solo per esempio, e ci sono vari modo di usare la query:

//Get the latest post ID number / / Get the latest post numero ID
$post->ID ORDER BY post_date ASC LIMIT 1 $ post-> ID ORDER BY post_date ASC limite 1

//Get the earliest post ID number / / Get prima post numero ID
$post->ID ORDER BY post_date DESC LIMIT 1 $ post-> ID ORDER BY post_date DESC limite 1

IMPORTANT : This is a machine translated page which is provided "as is" without warranty. IMPORTANTE: Questa è una pagina tradotta macchina che è fornito "così com'è" senza alcuna garanzia. Machine translation may be difficult to understand. Traduzione automatica può essere difficile da capire. Please refer to Si prega di fare riferimento a original English article articolo originale inglese whenever possible. quando possibile.

Share and contribute or get technical support and help at Condividere e contribuire o ottenere supporto tecnico e assistenza in My Digital Life Forums La mia vita digitale Forum .



13 Responses to “Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable” 13 risposte al "Recupero e Ottieni WordPress Post ID Al di fuori del Loop come PHP Variabile"

  1. Joel P Joel P
    December 1st, 2006 06:06 1 ° dicembre 2006 06:06
    1

    This is really good thing to know… I think i’ll try to use this with my blog and limited php knowledge. Questo è veramente cosa buona sapere… Credo di Cercherò di utilizzare questo con il mio blog e php limitata conoscenza.

  2. Matt
    May 3rd, 2007 05:10 3 maggio 2007 05:10
    2

    Just what I was looking for, thanks! Proprio quello che stavo cercando, grazie!

  3. Christophe
    May 16th, 2007 14:15 16 maggio 2007 14:15
    3

    Found this through Google. Trovato questo tramite Google. Thanks! Grazie! You should also enter this into the official WP documentation wiki: Si dovrebbe anche entrare in questo la documentazione ufficiale di WP wiki: http://codex.wordpress.org/Main_Page

  4. k
    June 28th, 2007 11:55 28 giugno 2007 11:55
    4

    Great info. Grande Info. Needed this a few days ago. Bisogno di questo pochi giorni fa. Will update my code with this direct approach. Aggiornerà il mio codice con questo approccio diretto. Thanks. Grazie.

  5. Eric
    September 21st, 2007 07:51 21 settembre 2007 07:51
    5

    Thanks, using ‘global $id;’ in a filter for my plugin got me the post id I needed. Grazie, usando 'global $ id;' in un filtro per il mio plug got me il posto id avevo bisogno.

  6. Osordvibil
    October 6th, 2007 00:09 6 ottobre 2007 00:09
    6

    comment_fashion

  7. 让WP不同页面使用不同设计 | 收拾起大地山河一担装让WP不同页面使用不同设计|收拾起大地山河一担装
    October 10th, 2007 21:05 Ottobre 10, 2007 21:05
    7

    [...] 使用post ID变量可以做到。$post->ID可以返回文章的唯一编号。 [...] [...]使用post ID变量可以做到. $ Post-> ID可以返回文章的唯一编号. [...]

  8. Reviews Recensioni
    April 18th, 2008 18:11 18 aprile 2008 18:11
    8

    Thanks! Grazie! That’s just what i am looking for. Questo è solo quello che sto cercando. I want to get post id on the wordpress index (root) page. Voglio arrivare post id sulla wordpress indice (root).

  9. Shops Negozi
    May 6th, 2008 20:02 6 maggio 2008 20:02
    9

    Thanks for this. Grazie per questo. You cant believe how long it took me to search for this simple answer! Cant si crede per quanto tempo mi ci sono voluti per la ricerca di questa risposta semplice! I dont know why you cant find it on wordpress. I dont know why cant si trovano a wordpress.

  10. Johannes
    June 16th, 2008 03:27 16 giugno 2008 03:27
    10

    Hi, Salve,
    thanks for these informations. grazie per queste informazioni.
    I tried to configure something without any luck and hope you can help me. Ho provato a configurare qualcosa senza un po 'di fortuna e di speranza potete aiutarmi.
    I’m using wordpress as a blog and do have a few pictures in every blog. Sto utilizzando wordpress come un blog e hanno poche immagini in ogni blog.
    Now I want to implement a feature like shadowbox to popup the images. Ora voglio realizzare una funzione simile a shadowbox di popup, le immagini. To do this automatically, I put a rel=”shadowbox[imageset]” in the anchors of the images. Per effettuare questa operazione automaticamente, metto un rel = "shadowbox [imageset]" nel ancore delle immagini.
    What do I have to do to put the post-title or ID instead of imageset. Che cosa devo fare per mettere il titolo post-ID o invece di imageset.
    Is something like this possible? Qualcosa di simile è possibile?

  11. Johannes
    June 16th, 2008 03:27 16 giugno 2008 03:27
    11

    Forgot Notification of followups. Hai dimenticato la Notifica di followups. Thanks. Grazie.

  12. PieterC
    June 17th, 2008 14:02 17 giugno 2008 14:02
    12

    Thank you. Grazie. It works like a charm! Funziona come un fascino!

  13. Daniel
    June 18th, 2008 09:34 Giugno 18, 2008 09:34
    13

    Thanks for this - this did absolutely what I needed to do. Grazie per questo - ha fatto questo assolutamente quello che avevo bisogno di fare. :)

Leave a Reply Lasciare una risposta

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> È possibile utilizzare questi tag: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime = ""> <em> <i> <q Cite=""> <strike> <strong>

Subscribe without commenting Iscriviti senza commentare


Custom Search

New Articles Nuovi articoli

Incoming Search Terms for the Article Cerca in arrivo Condizioni per l'articolo

wordpress post id WordPress post ID - -- wordpress get post id WordPress ottenere post ID - -- wordpress get page id WordPress ottenere ID pagina - -- post id wordpress ID post WordPress - -- wordpress page id WordPress pagina ID - -- get post ID Wordpress ID ottenere post Wordpress - -- $post->ID $ post-> ID - -- wordpress $post->id wordpress $ post-> ID - -- wordpress the_ID WordPress the_ID - -- wordpress get id WordPress ottenere ID - -- wordpress get current page id WordPress ottenere pagina corrente ID - -- wordpress post object WordPress post oggetto - -- wordpress get current page WordPress ottenere pagina corrente - -- wordpress current page id WordPress pagina corrente ID - -- page ID wordpress ID pagina WordPress - -- wordpress post_id WordPress post_id - -- wordpress get category id WordPress ottenere ID categoria - -- wordpress if post id WordPress se post ID - -- $post->ID wordpress $ post-> ID wordpress - -- wordpress get post by id WordPress ottenere post da ID - -- wordpress post variable WordPress post variabile - -- wordpress get post WordPress ottenere post - -- wordpress current post id WordPress post corrente ID - -- get post id post ottenere ID - -- wordpress post->ID WordPress post-> ID - -- wordpress $post object WordPress $ post oggetto - -- wordpress postid WordPress postid - -- wordpress $post WordPress $ post - -- post id ID post - -- get id wordpress ottenere ID WordPress - -- wordpress post variables WordPress post variabili - -- wordpress get current post WordPress ottenere post corrente - -- get post id in wordpress ID ottenere post in WordPress - -- wordpress pageid WordPress pageId - -- wordpress $post variable WordPress variabile $ post - -- wordpress get current category id WordPress Recupera ID categoria - -- get page ID wordpress ottenere ID pagina WordPress - -- wordpress get current post id WordPress ottenere post corrente ID - -- wordpress get post category id WordPress ottenere post ID categoria - -- post->id post-> ID - -- wordpress $post_id WordPress $ post_id - -- wordpress page id outside loop WordPress ID pagina al di fuori della rete - -- get wordpress post id WordPress post ottenere ID - -- wordpress the_id() WordPress the_id () - -- wordpress get id of current page wordpress ottenere id di pagina corrente - -- wordpress get page by id WordPress pagina di ottenere ID - -- wordpress id post WordPress ID post - -- wordpress change post id WordPress cambiamento post ID - -- wordpress get posts WordPress ottenere posti - -- wordpress get title by id WordPress ottenere il titolo di ID - --