Hi,
How can I sort albums that newest album is at first and oldest is last. Right now oldest album is first and newest is last.

Comments

silkogelman’s picture

Title: Album soting » Media Gallery Album Sorting

Would be nice if this was a View, that way it's easily adaptable for every usecase.

silkogelman’s picture

Media module is heading for Views 3 support:
#962110: Add views handlers for the media field type

damiandab’s picture

I also didn't figured out, how can I change sorting of Gallery Albums. Even If I change the the post date of Gallery, the sorting doesn't change :(

Any help would be very appreciated.

Thanks,
Damian

damiandab’s picture

ok, I found it. The media gallery sorts albums not by date but by media gallery weight.

media_gallery.module - function at line 1189

/**
 * Media gallery equivalent to taxonomy_select_nodes().
 */
function media_gallery_select_galleries($tid, $pager = TRUE, $limit = FALSE) {
  if (!variable_get('taxonomy_maintain_index_table', TRUE)) {
    return array();
  }
  $query = db_select('taxonomy_index', 't');
  $query->leftJoin('media_gallery_weight', 'mgw', 'mgw.nid = t.nid AND mgw.tid = :tid', array(':tid' => $tid));
  $query->addTag('node_access');
  $query->condition('t.tid', $tid);
  if ($pager) {
    $count_query = clone $query;
    $count_query->addExpression('COUNT(t.nid)');

    $query = $query->extend('PagerDefault');
    if ($limit !== FALSE) {
      $query = $query->limit($limit);
    }
    $query->setCountQuery($count_query);
  }
  else {
    if ($limit !== FALSE) {
      $query->range(0, $limit);
    }
  }
  $query->addField('t', 'nid');
  $query->addField('t', 'tid');
  $query->addField('mgw', 'weight');
  $query->orderBy('mgw.weight', 'ASC');
  $query->orderBy('t.nid', 'ASC');
  $result = $query->execute();
  return $result->fetchCol();
}

To change the sorting, from newest to oldest album, replace these lines :

  $query->orderBy('mgw.weight', 'ASC');
  $query->orderBy('t.nid', 'ASC');

with:

  $query->orderBy('mgw.weight', 'DESC');
  $query->orderBy('t.nid', 'DESC');
damiandab’s picture

Would be nice to expose media gallery weight to could manage custom sorting or make functional drag&drop sorting for albums.

nesca’s picture

what about sorting by date?

cntour’s picture

thanks a lot #4. It worked for albums order.
what about photos in one gallery? I need those photos newly uploaded to be displayed first in the gallery. Is it possible?

TY

mfgr’s picture

Strange thing is, I have been working with Media Gallery for a few weeks now but I can't seem to get this sorting in order. I tried manipulating the weight of the galleries I have but the front page, which displays all galleries, does not change at all. I have Media Gallery and Media installed, the current versions (updated today) and still nothing.
Since I have a new website and everything is still pretty clean, I have no idea what I'm doing wrong. Am I just overlooking something ?

claudio_s’s picture

Title: Media Gallery Album Sorting » Media Gallery Album Sorting - Sort By Title WorkAround

Exposing weight is the ultimate solution. In the meantime, sorting by title works best for my needs.

If you want to sort by title, make the following modifications to media_gallery.module

Find the function " media_gallery_select_galleries "

FIND: $query->leftJoin('media_gallery_weight', 'mgw', 'mgw.nid = t.nid AND mgw.tid = :tid', array(':tid' => $tid));

ADD The following below: 
/** Join to the node table from mgw to allow use of the title **/
  $query->Join('node', 'n', 'mgw.nid = n.nid');

FIND:   $query->addField('t', 'tid');
ADD the following below:
  /** Add the node title to the query **/
  $query->addField('n', 'title');  

FIND:   $query->orderBy('mgw.weight', 'ASC');
           $query->orderBy('t.nid', 'ASC'); 
COMMENT out these lines then ADD the following:

  /**  By default media gallery albums are sorted by weight, sort them alphabetically instead. **/
  $query->orderBy('n.title', 'ASC');
KungLi’s picture

After trying #9 my gallery page was empty, no more galleries were shown.

sterndata’s picture

#4 worked for me. I'd love to see the settings exposed.

csc4’s picture

Issue summary: View changes

I'm using Media Gallery 7.x-2.x-dev and dragging the galleries on the /galleries page is working for me to reorder as wished - if that helps anyone.

xavier19’s picture

Hello Friends,
is it possible to sort albums in media gallery by date? Thank you for any help ;)

ivnish’s picture

Status: Active » Closed (outdated)