3
07/11/2024 8:43 am
Inicio del tema
Hola - Me gustaría saber cómo mostrar todas las URLs de todos los posts (o/y páginas) de un sitio (el CMS es WordPress).
Algo así como XML sitemap pero mostrando todas las páginas permalinks en una página WP.
Tal vez como function....
Gracias
1 respuesta
2
07/11/2024 8:45 am
Este es el código:
$allPostsWPQuery = new WP_Query( array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => - 1
) ); ?>
<?php if ( $allPostsWPQuery->have_posts() ) : ?>
<ul>
<?php while ( $allPostsWPQuery->have_posts() ) : $allPostsWPQuery->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_permalink(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'There no posts to display.' ); ?></p>
<?php endif; ?>
En la línea #2 en lugar de:
'post_type'=>'page'
puedes teclear:
'post_type'=>'post'
para ver todas las entradas de su sitio.
Aquí está el resultado en el navegador:

