Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable Recuperar y obtener WordPress Post ID fuera del bucle como variable de PHP
In WordPress, each post has unique anchor identifier in the form of numeric post ID. En WordPress, cada puesto tiene identificador único ancla en forma de post ID numérico. 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. Cuando dentro del bucle, donde los procesos de WordPress y muestra cada uno de los puestos que se mostrará en la página actual y formatos de acuerdo a la forma en que coincidan con los criterios especificados en el bucle etiquetas, etiqueta the_ID plantilla se puede utilizar para mostrar fácilmente el puesto de la ID en el interior del puesto. Alternatively, inside the the_content filter, declare $id global and use $id to retrieve the post ID. Por otra parte, dentro de la the_content filtro, declarar $ id global y el uso de dólares id para recuperar el puesto de identificación.
the_ID template tag can be used in the following format: the_ID plantilla etiqueta se puede utilizar en el siguiente 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. Fuera del bucle o fuera del contexto del puesto, como en la cabecera de pie de página e incluso lateral en la zona de plantillas de WordPress en el blog, the_ID () no puede utilizarse como una función. 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). En cambio, $ post-> ID se utilizará para devolver el puesto de ID (la sintaxis puede ser también utilizados en el interior del Loop del puesto de dólares se declara como puesto mundial). $post is a global object that holds various information about the posts displayed on the page. $ cargo es un objeto global que mantiene información acerca de los puestos aparecen en la página. So $post->ID will return the post ID of the post. Por lo tanto, $ post-> ID devolverá el puesto de identificación del puesto. It the $post is used inside a function, the $post has to be declared as a global variable. Es el puesto de dólares se utiliza dentro de una función, el puesto de dólares tiene que ser declarado como una variable global. For example: Por ejemplo:
// Works inside of the Loop / / Funciona dentro del Loop
function function_name() { función function_name () (
global $post; global $ post;
$thePostID = $post->ID; thePostID $ = $ post-> ID;
} )
or: O bien:
// Works in single post outside of the Loop / / Obras en el único puesto fuera de la Loop
function function_name() { función 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 puede ser llamado directamente fuera del Loop demasiado en un solo puesto de plantilla, como por ejemplo <? php echo $ post-> ID> imprimirá la pantalla posterior del número de identificación.
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. En la opinión de varios puestos de página como página de índice o página de archivo, es posible recuperar el obtener la última antes o después de identificación de todos los puestos que aparecen en la página mediante el uso de una cláusula ORDER BY para ordenar los puestos de la fecha, y entonces ajustar el número de registro para limitar 1.
Just for example, and there are various way to use the query: Sólo por ejemplo, y hay varias manera de utilizar la consulta:
//Get the latest post ID number / / Obtener el último mensaje número de identificación
$post->ID ORDER BY post_date ASC LIMIT 1 $ post-> ID ORDER BY post_date ASC LIMIT 1
//Get the earliest post ID number / / Obtener los primeros puestos número de identificación
$post->ID ORDER BY post_date DESC LIMIT 1 $ post-> ID ORDER BY post_date DESC LIMIT 1
IMPORTANT : This is a machine translated page which is provided "as is" without warranty. IMPORTANTE: Se trata de una máquina que traduzca la página se proporciona "tal cual" sin garantía. Machine translation may be difficult to understand. La traducción automática puede resultar difícil de entender. Please refer to Por favor, consulte original English article artículo original Inglés whenever possible. siempre que sea posible.
Share and contribute or get technical support and help at Compartir y contribuir o recibir apoyo técnico y ayudar a My Digital Life Forums Mi vida digital Foros .
Related Articles Artículos relacionados
- Paginating or Split WordPress Post or Page with NextPage in WordPress Not Working Paginating Split o WordPress Post o con NextPage en WordPress no funciona
- Disable and Turn Off Post Revisions Tracking in WordPress 2.6 or Above Inhabilitar y apagar Post revisiones de seguimiento en WordPress 2,6 o Superior
- How to Change the Frequency or Interval WordPress Auto Saves An Editing Post or Page Cómo cambiar la frecuencia o intervalo de WordPress Auto guarda una edición posterior o la página
- WordPress MySQL SQL Query Error in WPDB Class WordPress MySQL consulta SQL Error en la clase WPDB
- Adding Extra More Fields to WordPress Write/Edit Post/Page Right Column Añadir más campos extra para WordPress escribir y editar los mensajes / Page columna derecha
- Disable Auto Go To (Jump) To Read More Tag Desactivar Auto ir a la (Ir) para leer más etiqueta
- How To Store Every Post Revisions on Each Auto-Save in WordPress with Limit on Versions Count Cómo almacenar todas las revisiones posteriores a cada Auto-salvo en WordPress con el límite de contar con versiones
- 3 Column Relaxation WordPress Theme comments-paged.php for Paged-Comments WordPress Plugin Columna 3 Relajación WordPress-Tema comentarios paged.php para Paged-Comentarios WordPress Plugin
- How to Delete Existing WordPress Post Revisions Stored/Saved ¿Cómo borrar los existentes WordPress revisiones posteriores almacenados / guardado
- Integrate WordPress including Comments with bbPress Forum using bbSync Integrar la inclusión de los comentarios de WordPress con bbPress Foro utilizando bbSync



















December 1st, 2006 06:06 1 de diciembre de 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. Esto es realmente bueno saber… creo que voy a tratar de usar esto con mi blog y la escasez de conocimientos php.
May 3rd, 2007 05:10 3 de Mayo de 2007 05:10
Just what I was looking for, thanks! Justo lo que yo estaba buscando, gracias!
May 16th, 2007 14:15 16 de mayo de 2007 14:15
Found this through Google. Encontrado esto a través de Google. Thanks! Gracias! You should also enter this into the official WP documentation wiki: Usted también debe entrar en esto en la documentación oficial WP wiki: http://codex.wordpress.org/Main_Page
June 28th, 2007 11:55 28 de junio de 2007 11:55
Great info. Gran Info. Needed this a few days ago. Necesario este hace unos días. Will update my code with this direct approach. ¿Actualizar mi código con este enfoque directo. Thanks. Gracias.
September 21st, 2007 07:51 21 de septiembre de 2007 07:51
Thanks, using ‘global $id;’ in a filter for my plugin got me the post id I needed. Gracias, usando 'global $ id; "en un filtro para mi plugin me consiguió el puesto que necesitaba id.
October 6th, 2007 00:09 6 de octubre de 2007 00:09
comment_fashion
October 10th, 2007 21:05 10 de Octubre de 2007 21:05
[...] 使用post ID变量可以做到。$post->ID可以返回文章的唯一编号。 [...] [...]使用post ID变量可以做到. $ Post-> ID可以返回文章的唯一编号. [...]
April 18th, 2008 18:11 18 de abril de 2008 18:11
Thanks! Gracias! That’s just what i am looking for. Eso es justo lo que estoy buscando. I want to get post id on the wordpress index (root) page. Quiero obtener id puesto en el índice de wordpress (raíz).
May 6th, 2008 20:02 Mayo 6, 2008 20:02
Thanks for this. Gracias por ello. You cant believe how long it took me to search for this simple answer! Usted peralte creer cuánto tiempo me llevó a la búsqueda de esta simple respuesta! I dont know why you cant find it on wordpress. I dont saber por qué le parece peralte en wordpress.
June 16th, 2008 03:27 El 16 de junio de 2008 03:27
Hi, Hola,
thanks for these informations. gracias por estas informaciones.
I tried to configure something without any luck and hope you can help me. He intentado configurar algo sin suerte y espero que usted me puede ayudar.
I’m using wordpress as a blog and do have a few pictures in every blog. Estoy usando wordpress como un blog y tienen unas cuantas fotos en todos los blogs.
Now I want to implement a feature like shadowbox to popup the images. Ahora quiero aplicar una función como shadowbox popup a las imágenes. To do this automatically, I put a rel=”shadowbox[imageset]” in the anchors of the images. Para hacer esto automáticamente, poner un rel = "shadowbox [imageset]" en los anclajes de las imágenes.
What do I have to do to put the post-title or ID instead of imageset. ¿Qué tengo que hacer para poner el post-título o de documento de identidad en lugar de imageset.
Is something like this possible? Es algo como esto posible?
June 16th, 2008 03:27 El 16 de junio de 2008 03:27
Forgot Notification of followups. ¿Ha olvidado Notificación de Followups. Thanks. Gracias.
June 17th, 2008 14:02 17 de junio de 2008 14:02
Thank you. Gracias. It works like a charm! Funciona como un encanto!
June 18th, 2008 09:34 18 de junio de 2008 09:34
Thanks for this - this did absolutely what I needed to do. Gracias por este - este hecho absolutamente lo que necesitaba hacer.