Hey @Ruriko … its a 3 step action.
- get the current category ID
- get the posts for this specific category
- get the posts into a select menu
Please note that this code would use the first
category id altough you might assign several
categories to the same post.
.
<?php
// FIRST CATEGORY NAME
$category = get_the_category();
$catID = $category[0]->term_id;
$args = array(
'numberposts' => 5,
'category' => $catID
);
$catPosts = get_posts( $args );
echo '<form method="POST">';
echo '<select name="goToPost" onchange="document.location=this.value">';
echo '<option value="">'.__('Relevent Posts', 'your_text_domain').'</option>';
foreach( $catPosts as $singlePost ) {
echo '<option value="'.get_bloginfo('url').'/index.php?p='.$singlePost->ID.'">'.$singlePost->post_title.'</option>';
};
echo '</select>';
echo '</form>';
?>
Hope this helps.
Cheers, Sagive.