Are you looking for a way to display a list of all your posts within a dropdown menu? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display all posts within a dropdown menu in WordPress.
You can adjust the number of posts displayed by changing the
-1 value within the
All you have to do is add this code to your theme’s index.php file:
<form action="<? bloginfo('url'); ?>" method="get"> <select name="page_id" id="page_id"> <?php global $post; $args = array( 'numberposts' => -1); $posts = get_posts($args); foreach( $posts as $post ) : setup_postdata($post); ?> <option value="<? echo $post->ID; ?>"><?php the_title(); ?></option> <?php endforeach; ?> </select> <input type="submit" name="submit" value="view" /> </form>
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.