Home › Forums › Add-ons › Gallery Field › ordering images of a gallery according to datepicker inside attachment page › Reply To: ordering images of a gallery according to datepicker inside attachment page
i found a part of the code.
The probleme is i store the year in a variable and when the loop see an other year, it’s erase the year to an other one.
So i get many time the same year and the systeme dont put all the images who have the same year in the same header.
here is my code
<?php
$post_id = "option"; // options page
$gallery = get_field('galerie_archive', $post_id);
// vars
$order = array();
// populate order
foreach( $gallery as $i => $image ) {
$order[ $i ] = $image['id'];
}
// multisort
array_multisort( $order, SORT_DESC, $gallery );
// loop through gallery
if( $gallery ):
$current_header = ''; ?>
<?php foreach( $gallery as $i => $image ):
$date = get_field('date', $image['ID'], false);
$temp_header = date_i18n('Y', strtotime($date));
if ( $temp_header != $current_header ) {
$current_header = $temp_header;
echo "<h3>".$current_header.'</h3>';
}
?>
<div>
<img src="<?php echo $image['sizes']['medium']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php the_field('date', $image['ID']); ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.