Hey guys!
I am building a wordpress install for the purpose of storing fan fiction archives.
I have coded up a drop down box that basically will if it finds more than 1 post with the same name, list them in a drop down list so the user can select a chapter (they are organised into episodes via a tag, i.e; 1x01, 1x02).
Here is the code I am using to generate the drop down.
<?php
$counter = '1';
echo '<form action="../">
<select onchange="window.open(this.options[this.selectedIndex].value,\'_top\')">
<option value="">Choose a chapter...</option>';
$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);
echo '<option value="' , the_permalink() , '">Chapter ' , $counter++ , '</option>\n';
endforeach;
else :
endif;
echo '</select></form>';
?>
What I am trying to do and am getting confused because it doesn't seem to work, is this.
I would like to first count how many entries there are, for example if there is only 1 result, I do not wish the dropdown to not output. If there is more than 1 result, then go ahead and output it.
I tried changing if ($chapters) : to if ( $chapters > 1 ) : but this did not work.
It's taken me the better part of a day or so just to wriggle the above code to the point it stands at, I'm quite new to PHP.
Can anyone offer any alternative coding that I could use? Or a better coded solution?
Many thanks for reading!