The WordPress website that I am creating has an Frequently Asked Questions page. Each question/answer pair is created via use of the SiteOrigin Page Builder Plugin and a custom widget. I would like to be able to add new questions and rearrange them without needing to manually renumber.
This is how it looks right now:
I would simply like the questions to be dynamically numbered (1., 2., 3., and soforth, just before the question).
I can think of some hack-ish ways that might accomplish this task, like abusing an <ol>
tag or global variable. I might also be able to use some code to count the number of elements that have been created with the class "question", but it feels like that would add unnecessary code/latency to what should possible with a simple integer variable that exists only while this page is being rendered.
Is possible in WordPress? If so, how do I accomplish it? If not, is there a better method than what I have mentioned?
If it helps, here's the render code from my widget's PHP file:
public function widget( $args, $instance )
{
$question = $instance['question'];
$answer = $instance['answer'];
echo $args['before_widget'];
if ( ! empty( $question ) )
{
echo '<h3 class="question">';
echo '. ';
echo $question;
echo '</h3>';
}
if ( ! empty( $answer ) )
{
echo '<p>';
echo $answer;
echo '</p>';
}
echo $args['after_widget'];
}