Back WordPress

Create Dropdown List of Posts from a Category

WRITTEN BY ON 07 Feb 2011

You want to list posts from a category but don’t have much space for the list in your site? Simple, make the list in a dropdown box. Here, I’ll share the code to create this dropdown box. Also, as the result of this code, when the post in the list is selected, the user will be taken to that post.


Place the code below in your sidebar or wherever you want to put the list, in your site :
In this code, posts are from ‘uncategorized’ category. You can change the category to meet your needs.
If the list is to wide, you can set the width of select tag of the code via css.

	$cat_id = get_cat_ID('uncategorized');
	  'cat' => $cat_id,
	  'post_type' => 'post',
	  'post_status' => 'publish',
	  'posts_per_page' => -1,
	  'caller_get_posts'=> 1
	$my_query = null;
	$my_query = new WP_Query($args);
	if( $my_query->have_posts() ) {
	<form name="jump">
		<select name="menu">
			  while ($my_query->have_posts()) : $my_query->the_post(); ?>
				<option value="<?php the_permalink() ?>"><?php the_title(); ?></option>

		<input type="button" onClick="[].value;" value="Go">


Join the discussion

Comments will be moderated and rel="nofollow" will be added to all links. You can wrap your coding with [code][/code] to make use of built-in syntax highlighter.