Problem: some of the post titles on my WordPress site are questions, i.e. the post title ends with a question mark. And I have post queries that generate lists of the most recent posts. So I'm trying to figure out a bit of php that will keep my punctuation correct.
What's a good way to determine if the last character of a title is a question mark and not echo a period? And if the post title is a not a question, echo a period.
This is what I am trying to use to get the title in a wordpress query and then determine if the title is a question, but it doesn't print the period.
Must be something simple I have wrong here:
<?php $mytitle = get_the_title(); echo $mytitle; ?>
<?php $question = substr($mytitle, -1); if (!$question = '?'): echo '.'; endif; ?>
Edit 3/03/10
This now works:
<?php $mytitle = get_the_title(); echo $mytitle; ?>
<?php $question = substr($mytitle, -1); if ($question != '?') { echo '.'; } ?>