Piwigo.org

You are not logged in. (Register / Login)

Announcement

#1 2011-04-28 20:20:46

bjordan
Member
Registered: 2011-04-25
Posts: 30

[resolved] Change Sort Order Options

Is there a way within a theme to change the sort order options? I found where to change them in the core code, however I'm trying to avoid making any changes there so I don't have issues when I upgrade in the future.

I'd like to make my own sort order options such as:

Oldest First
Newest First

and remove sort by rating (I plan to remove ratings), etc.

I'll keep looking into it tonight, but any advice is appreciated.

Offline

#2 2011-04-28 23:45:19

lisaviolet
Member
Location: san diego, california
Registered: 2011-01-03
Posts: 310
Website

Re: [resolved] Change Sort Order Options

Don't make changes to the core.  If you do and Piwigo is updated, all of your changes will be overwritten.  That said....

You can change sort order by category.

Admin > Albums > Manage >

Go to the album/category you want to change.  To edit this album, click on the little tools.  If it's a sub-album, click on the little folder.  At the top of that page, you should see the name of the album you're working on. There will be a little orange ball with an arrow, the next will be four green circles on top of one another, with an arrow pointing down.  Click on that.  You can set up the sort order there.

Or use the edit function in the album, that will take you to the edit page. 

Or you can use the localfiles editor and edit local/config/config.inc.php.  Refer to the misc section of the link at the top right of the textarea  ("Display reference file: "config_default.inc.php") for sort order.

Offline

#3 2011-04-29 18:04:46

bjordan
Member
Registered: 2011-04-25
Posts: 30

Re: [resolved] Change Sort Order Options

lisaviolet, thanks! Again you've been a huge help. I messed with the album editor quite a bit. However I never noticed the per album sort options. That helped me out a lot as I do want different sort orders for certain albums.

I'm also aware of not making edits to CORE as it'll cause issues with an upgrade and/or I'll lose those changes.

Is there any way to change the actual sort options that show up in the dropdown when viewing the album? The defaults are:

Default
Average rate
Most visited
Creation date
Post date
File name
Rank
Permissions

I'd like to simplify the list and customize it to only have these options:

Default
Oldest First (<== Creation date ascending)
Newest First (<== Creation date descending)

Last edited by bjordan (2011-04-29 18:05:10)

Offline

#4 2011-04-29 18:39:34

lisaviolet
Member
Location: san diego, california
Registered: 2011-01-03
Posts: 310
Website

Re: [resolved] Change Sort Order Options

I don't think you can do that without messing with the core, but one of the developers would better know the answer to that question.

Offline

#5 2011-04-29 19:11:53

rvelices
Piwigo Team
Registered: 2005-12-29
Posts: 1554
Website

Re: [resolved] Change Sort Order Options

you could do your changes in a plugin. here is what the core does:

Code:

  return trigger_event('get_category_preferred_image_orders',
    array(
    array(l10n('Default'), '', true),
    array(l10n('Average rate'), 'average_rate DESC', $conf['rate']),
    array(l10n('Most visited'), 'hit DESC', true),
    array(l10n('Creation date'), 'date_creation DESC', true),
    array(l10n('Post date'), 'date_available DESC', true),
    array(l10n('File name'), 'file ASC', true),
    array(
      l10n('Rank'),
      'rank ASC',
      ('categories' == @$page['section'] and !isset($page['flat']) and !isset($page['chronology_field']) )
      ),
    array( l10n('Permissions'), 'level DESC', is_admin() )
    ));

your plugin event handler function that will receive the default array and you could return yours... I advise you to leave the Default. This is a special case where some albums could have different sort orders. Also in the default mode, the quick search results will be sorted automatically by relevance...

Offline

#6 2011-04-29 20:01:36

bjordan
Member
Registered: 2011-04-25
Posts: 30

Re: [resolved] Change Sort Order Options

rvelices wrote:

you could do your changes in a plugin. here is what the core does:

I found that code in CORE but wanted to avoid making changes to CORE so I was looking for an alternative way. I'll look into making a plugin to handle this. I really appreciate you pointing me in the right direction.

Offline

#7 2011-04-30 00:16:59

P@t
Piwigo Team
Location: Nice
Registered: 2007-06-13
Posts: 4092
Website

Re: [resolved] Change Sort Order Options

In a personal plugin, insert this code:

Code:

add_event_handler('get_category_preferred_image_orders', 'personal_category_preferred_image_orders');

function personal_category_preferred_image_orders($order)
{
  return array(
    array(l10n('Default'), '', true),
    array(l10n('Oldest First'), 'date_creation ASC', true),
    array(l10n('Newest First'), 'date_creation DESC', true),
  );
}

P@t

Offline

#8 2011-05-01 01:58:26

bjordan
Member
Registered: 2011-04-25
Posts: 30

Re: [resolved] Change Sort Order Options

P@t, thanks for the response. With your code and the plugin documentation I was able to get this up and going in about 5 minutes.

I really appreciate the all the help everyone has given me. I'm impressed with the fast and helpful responses I've been getting related to this project. I'm definitely quickly becoming more and more of a Piwigo fan.

You guys really seem to have a nice event handler structure in place that makes implementing things pretty straight forward. As a fellow developer I really appreciate that.

Offline

#9 2011-05-01 07:44:24

ddtddt
Piwigo Team
Location: Quetigny - France
Registered: 2007-07-27
Posts: 6075

Re: [resolved] Change Sort Order Options

bjordan wrote:

I'm definitely quickly becoming more and more of a Piwigo fan.

:-)

Can you pass topic to resolved - link in the first post ;-)


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Online

#10 2011-07-01 23:58:13

bjordan
Member
Registered: 2011-04-25
Posts: 30

Re: [resolved] Change Sort Order Options

I'm cross posting this here as well in case anyone runs across this thread and is trying to do the same thing. I submitted the plugin to the Extensions repository that solves this.

[extension by bjordan] Simple Sort Orders

Last edited by bjordan (2011-07-01 23:58:31)

Offline

Board footer

Powered by FluxBB

About this website · Donate · Contact Piwigo project © 2002-2013