the page name loop description content codex php wordpress

php - page - ¿Usar Wordpress LOOP con páginas en lugar de publicaciones?



wordpress php get post title by id (2)

¿Hay alguna manera de usar THE LOOP en Wordpress para cargar páginas en lugar de publicaciones?

Me gustaría poder consultar un conjunto de páginas secundarias y luego usar las llamadas a la función THE LOOP - cosas como the_permalink() y the_title() .

¿Hay alguna forma de hacer esto? No vi nada en la documentación de query_posts() .


Dada la edad de esta pregunta, quería proporcionar una respuesta actualizada para cualquier persona que se tropiece con ella.

Sugeriría evitar query_posts. Esta es la alternativa que prefiero:

$child_pages = new WP_Query( array( ''post_type'' => ''page'', // set the post type to page ''posts_per_page'' => 10, // number of posts (pages) to show ''post_parent'' => <ID of the parent page>, // enter the post ID of the parent page ''no_found_rows'' => true, // no pagination necessary so improve efficiency of loop ) ); if ( $child_pages->have_posts() ) : while ( $child_pages->have_posts() ) : $child_pages->the_post(); // Do whatever you want to do for every page. the_title(), the_permalink(), etc... endwhile; endif; wp_reset_postdata();

Otra alternativa sería utilizar el filtro pre_get_posts, pero esto solo se aplica en este caso si necesita modificar el ciclo primario. El ejemplo anterior es mejor cuando se usa como un bucle secundario.

Lectura adicional: http://codex.wordpress.org/Class_Reference/WP_Query


Sí, eso es posible Puede crear un nuevo objeto WP_Query. Haz algo como esto:

query_posts(array(''showposts'' => <number_of_pages_to_show>, ''post_parent'' => <ID of the parent page>, ''post_type'' => ''page'')); while (have_posts()) { the_post(); /* Do whatever you want to do for every page... */ } wp_reset_query(); // Restore global post data

Además : hay muchos otros parámetros que se pueden usar con query_posts. Algunos, pero desafortunadamente no todos, se enumeran aquí: http://codex.wordpress.org/Template_Tags/query_posts . Al menos post_parent y más importante post_type no están listados allí. ./wp-include/query.php las fuentes de ./wp-include/query.php para averiguar sobre esto.