3
07/11/2024 8:43 am
Старт на темата
Hi - I would like to know how to show all the URLs of all the posts (or/and pages) of a site (the CMS is WordPress).
Something like XML sitemap but showing all the pages permalinks on one WP page.
Maybe as a function....
Благодаря
1 Отговор
2
07/11/2024 8:45 am
Ето кода:
$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; ?>
On line #2 instead of:
'post_type'=>'page'
you can type:
'post_type'=>'post'
to see all the posts of your site.
Here is the result in the browser:

