Hello people, I've managed through much toil to come up with the following code, I am running a wordpress blog and I am using a loop to display a drop down list for chapter navigation purposes (it will be a fan fiction site) but I would like it adapted to be able to check first if there is more than 1 post of the same name, and if there is to display the relevant drop down, if there is only 1 then do not display the drop down.
Here is the code I'm working with.
<?php $counter = '1'; ?>
<form action="../">
<select onchange="window.open(this.options[this.selectedIndex].value,'_top')">
<option value="">Choose a chapter...</option>
<?php
$chapters = $wpdb->get_results("SELECT * FROM $wpdb->posts
WHERE post_title = '" . $post->post_title . "' AND post_status = 'publish' ORDER BY post_date");
if ($chapters) :
foreach ($chapters as $post) :
setup_postdata($post);
?>
<option value="<?php the_permalink(); ?>">Chapter <?php echo $counter++; ?></option>
<?php
endforeach;
else :
?>
<h2> Not Found</h2>
<?php endif; ?>
</select>
</form>
Also if you can improve the code in some manner please give me your suggestions (I know using the counter variable to increment the chapter numbers in the drop down is kind of hacky/tacky lol).
I'm guessing I would need whatever counting code to be in the top bit and in the else bit the actual code to display the drop down, but I am unsure of the syntax required or the code.
Thanks for any help you guys can provide!