3
07/11/2024 8:43 am
Argomento iniziale
Salve - Vorrei sapere come mostrare tutti gli URL di tutti i post (o/e pagine) di un sito (il CMS è WordPress).
Qualcosa di simile alla sitemap XML, ma che mostri tutti i permalink delle pagine su una pagina WP.
Forse come function....
Grazie
1 risposta
2
07/11/2024 8:45 am
Ecco il codice:
$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; ?>
Alla riga #2 invece di:
'post_type'=>'page'
è possibile digitare:
'post_type'=>'post'
per vedere tutti i post del vostro sito.
Ecco il risultato nel browser:

