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 .
Related Articles Articoli correlati
- Paginating or Split WordPress Post or Page with NextPage in WordPress Not Working Paginating o Split WordPress Post o con Nextpage in WordPress non funzionante
- Disable and Turn Off Post Revisions Tracking in WordPress 2.6 or Above Disattivare e disattivare Post Revisioni di monitoraggio in WordPress 2,6 o superiore
- How to Change the Frequency or Interval WordPress Auto Saves An Editing Post or Page Come cambiare la frequenza o intervallo di WordPress Auto salva una modifica di post o pagina
- WordPress MySQL SQL Query Error in WPDB Class WordPress mysql query SQL errore nella classe WPDB
- Adding Extra More Fields to WordPress Write/Edit Post/Page Right Column Aggiungendo più campi extra per scrivere wordpress / Modifica post / pagina colonna di destra
- Disable Auto Go To (Jump) To Read More Tag Disabilitata l'auto per andare (vai) per saperne di più tag
- How To Store Every Post Revisions on Each Auto-Save in WordPress with Limit on Versions Count Come conservare ogni post revisioni su ogni auto-save in WordPress con limite di versioni count
- 3 Column Relaxation WordPress Theme comments-paged.php for Paged-Comments WordPress Plugin 3 colonne Relax WordPress Tema commenti-paged.php per paginati-Commenti WordPress Plugin
- How to Delete Existing WordPress Post Revisions Stored/Saved Come eliminare esistenti WordPress post revisioni memorizzati / salvato
- Integrate WordPress including Comments with bbPress Forum using bbSync Integrare WordPress compresi Commenti con bbPress Forum utilizzando bbSync

































December 1st, 2006 06:06 1 ° dicembre 2006 06:06
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.
May 3rd, 2007 05:10 3 maggio 2007 05:10
Just what I was looking for, thanks! Proprio quello che stavo cercando, grazie!
May 16th, 2007 14:15 16 maggio 2007 14:15
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
June 28th, 2007 11:55 28 giugno 2007 11:55
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.
September 21st, 2007 07:51 21 settembre 2007 07:51
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.
October 6th, 2007 00:09 6 ottobre 2007 00:09
comment_fashion
October 10th, 2007 21:05 Ottobre 10, 2007 21:05
[...] 使用post ID变量可以做到。$post->ID可以返回文章的唯一编号。 [...] [...]使用post ID变量可以做到. $ Post-> ID可以返回文章的唯一编号. [...]
April 18th, 2008 18:11 18 aprile 2008 18:11
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).
May 6th, 2008 20:02 6 maggio 2008 20:02
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.
June 16th, 2008 03:27 16 giugno 2008 03:27
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?
June 16th, 2008 03:27 16 giugno 2008 03:27
Forgot Notification of followups. Hai dimenticato la Notifica di followups. Thanks. Grazie.
June 17th, 2008 14:02 17 giugno 2008 14:02
Thank you. Grazie. It works like a charm! Funziona come un fascino!
June 18th, 2008 09:34 Giugno 18, 2008 09:34
Thanks for this - this did absolutely what I needed to do. Grazie per questo - ha fatto questo assolutamente quello che avevo bisogno di fare.