Nav menu of all posts in a custom post type

There are several ways to do this. Unless you are only going to have a few posts of type ‘section1’ then I would advise against listing them all.

Options:

Using the WP_Query() option:

<?php $posts = new WP_Query( array( 'post_type' => 'section1', 'posts_per_page' => -1 ) ); ?>

<ul>
<?php while( $posts->have_posts() ) : $posts->the_post(); ?>
    <li><a href="https://wordpress.stackexchange.com/questions/42325/<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>

<?php wp_reset_postdata(); ?>

Hope that helps!

If you are looking to dynamically create a nav-menu from the posts of a specific category, let’s say having the slug ‘featured’, then replace ‘post_type’ => ‘section1’ with ‘category_name’ => ‘featured’

Leave a Comment