Jump to content



Recommended Posts

Hey joey102030! I think kongondo's advice is necessity but not sufficiency to achieve what you need. You should add some js/jquery pligin on top of that wonderful module to make it work as accordion.

You download the js plugin and plug it in the template file like any js with <script>. Than customize the plugin and/or Markup Simple Navigation output options and you're done.

  • Like 1
Link to comment
Share on other sites

The module I have is too complicated to take apart right now. I have a lot of stuff going on that is specific to my local needs.

The easiest way to handle this is to put this in a template.

<?php $items = $pages->find('your_selector');?>

<dl class="accordion">
<?php foreach ($items as $item):?> 
    <dt><a href="<?php echo $item->url;?>"><?php echo $item->title;?></a></dt>
    <dd><?php echo $item->body;?></dd>
<?php endforeach;?>

Then include your own CSS/JS, or use the CSS/JS from my demo

If you need a nested accordion, then it's a little tricker, and would be easier with a recursive function. 

Link to comment
Share on other sites

Here's a quick recursive version. Written in the browser and untested.

Should give you a solid place to start.

function renderAccordion(pageArray $pages){
    $out = "<dl class='accordion'>";
    foreach ($pages as $page){
        $out .= "<dt><a href='$page->url'>$page->title</a></dt>";
        $out .= "<dd>";
        if ($page->numChildren){
            $out .= renderAccordion($page->children()); // go recursive
        } else
            $out .= $page->body;
       $out .= "</dd>";
    $out .= "</dl>";

    return $out;

$items = $pages->find("your_selector");
echo renderAccordion($items); 

This will just keep going. You could set it to accept a $levels argument that would stop it after a specified depth.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...