ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Is it possible to show previous and next record in FF Matrix?

October 07, 2009 7:26pm

Subscribe [3]
  • #1 / Oct 07, 2009 7:26pm

    gamma911

    51 posts

    I’ve asked this over at Brandon’s site also, but doing so here too incase there are some suggestions from the communtity over here.

    I am creating a photo gallery with Fieldframe matrix and Ngen file upload and the imgsizer plugin. Is it possible to show the next and previous image ( row ) for Fieldframe?
    Check flickr for an example.

  • #2 / Oct 13, 2009 6:47am

    gamma911

    51 posts

    Anyone got any ideas on how to achieve this?

  • #3 / Oct 13, 2009 10:24am

    ender

    1644 posts

    I created a multi-page article using FF matrix that had a table of contents and next/prev links.  The matrix had a title field and a WYMeditor field for the content.

    url structure was site.com/articles/<article-name>/<section-title>/ where articles was the template in the default template group, <article-name> was the url-title of the entry, and <section-title> was the title field from the FF matrix with all non-alphanumerics converted to hyphens, groups of hyphens converted to a single hyphen, leading and trailing hyphens stripped, and converted to lower case.

    for the nav and next/prev links I used a good bit of PHP.  every call to any subsection of an article required processing every entry in the matrix.  you keep track of the information from the previous entry so that when you find the one you’re looking for you can save the info into a previous link.  you also need to set a boolean when you find the entry you want so that you can capture the next entry’s information as a next link.  after you’ve got your matching info and your next/previous links you can exit fast from subsequent iterations through the matrix.

    I have no idea if this would scale well to hundreds or thousands of items, but the maximum I was going to have was on the order of 5-10 so it works for my purposes.

  • #4 / Oct 13, 2009 10:27am

    gamma911

    51 posts

    Mine would only ever have about 10 items, so it should work, any chance you can post some example code?

  • #5 / Oct 13, 2009 10:33am

    ender

    1644 posts

    sorry, can’t post this code and it would take me too long to clean it up into something I’d be able to post.

  • #6 / Nov 19, 2009 12:37am

    Peter Baker

    49 posts

    I needed to do the same thing. I did it by passing all the Matrix values into an array, then deciding what to do with it with some boolean flags.

    {photos}
        <?
        
        # Get FF Matrix values
        $current_loop = array(
            "file" => '{file}', 
            "title" => '{title}',
            "url_title" => '{url_title}'
        );
        
        # First Row
        if ({row_count} == 1): $first = $current_loop; endif;
        # Last Row
        if ({row_count} == {total_rows}): $last = $current_loop; endif;
        
        # We've passed the current page already, so grab this one as $next
        if ($end_time):
            $next = $current_loop;
            $end_time = false;
        endif;
        
        # We're on the current page's entry now
        if ('{segment_3}' == '{url_title}'):
            $current = $current_loop; # Save the current loop as the $current page
            $end_time = true; # Trip the switch to tell the next loop we've found $current
        endif;
        
        # We haven't set $current yet, so save current loop in $prev
        # once $current is set, we stop doing this, and $prev is untouched
        if(!isset($current)): $prev = $current_loop; endif;
        
        ?>
    {/photos}
            
    <div>
        <a href="/{segment_1}/{segment_2}/&lt?="> ?>/"]<?= $prev['title'] ?></a> 
        <?= $current['title']?>
        <a href="/{segment_1}/{segment_2}/&lt?="> ?>/"]<?= $next['title'] ?></a> 
    </div>

    Would love it if this was built in to FF Matrix.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases