Jump to content

Best way to pull array value associated with link selected?


n0sleeves
 Share

Recommended Posts

I have a repeating loop which displays tracks from an album with a link on each track pointing to lyrics which appear in a popup window. Well, that's what I want to do at least :P Here's the code which displays the track listings: 

           <?php // Show Album Tracks

            $albumTracks = $page->children;
        
            foreach ($albumTracks as $track) {
              $html = "<tr>";
              $html .= "<td>";
              $html .= "<a href='" . $track->song_file->url . "' class=''>" . $track->title . "</a>";
              $html .= "</td>";

              $html .= "<td>";
                if ($track->lyrics != null) { // LYRICS LINK
                    $html .= "<a href='#' data-reveal-id='lyricPopup'>Lyrics</a>";
                };
              $html .= "</td>";

              $html .= "<td>";
              $html .= "<a href='#'>Buy</a>";
              $html .= "</td>";
              $html .= "</tr>";

              echo $html;
            }
            ?>

The link is pointing to a modal popup div below:

<div id="lyricPopup" class="reveal-modal" data-reveal>
  <h2><?php echo $track->title; ?></h2>
  <?php

  ?>

  <a class="close-reveal-modal">×</a>
</div>

What I need to do is have each track's lyrics popup in the modal. Can anyone supply the code for setting up the multi-dimension array which keeps tracks of which song title (lyric link) was clicked so that the appropriate lyrics for that particular song (associated with that song) appear in the modal?

I understand the concept of arrays, but multidimensional are out my league. Knowing which link was clicked and retrieving the associated content for it is also beyond me. Not sure where to start. 

Thanks!!!

Link to comment
Share on other sites

Why aren't you just adding template file to each track and in there rendering the lyrics? Your modal link could point to the URL of the track page itself and then you'd just need some simple JS to open that as a modal window (or popup, whichever it is that you want).

.. and if you need to stick with current structure, you'll have to append track ID or some other method of identification to each modal divs id attribute (such as id="lyricPopup1234" where 1234 is ID of track page) and matching ID to each modal link (data-reveal-id="lyricPopup1234").

Based on your attributes there I'm assuming that you're using this plugin. They've got pretty good instructions for using the plugin, so please take a closer look at those first.

Edit: just saw what Soma posted in your other thread about this. Makes sense. Just stick with what you've got here :)

Edited by teppo
  • Like 2
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
 Share

×
×
  • Create New...