Hey @Ruriko ... its a 3 step action.
获取当前类别ID获取此特定类别的帖子将帖子放入选择菜单请注意,此代码将使用第一个类别ID,尽管您可以为同一帖子分配多个类别。。
<?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>\';
?>
希望这有帮助<干杯,萨吉夫。