Im working on an FAQ section for a client. It's using Foundations Accordian JS so you click a Question and it toggles the Answer. You know the deal.
The tricky part for me is when looping through my FAQs, I need to assign each anchor and target div with a unique number.
Been trying to set a variable at one and then incrementally add a number per each FAQ. Wondered if my syntax was wrong or if there are more basic issues with the $x=1 idea.
<a href='#$x++'>{$faq->title}</a>;
<div id='$x++' class='content'>
My working code (apart from the $x++)
<?php
$x=1; // Start a fairyball at 1
$faqs = $pages->find("template=faq-detail");
echo "<dl class='accordion' data-accordion>";
foreach ($faqs as $faq)
echo "
<dd class='accordion-navigation'>
<a href='#$x++'>{$faq->title}</a>;
<div id='$x++' class='content'>
{$faq->faq_body}
</div>
</dd>
";
echo"</dl>"
;?>