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.

Sorting question on custom field

October 29, 2007 5:40pm

Subscribe [3]
  • #1 / Oct 29, 2007 5:40pm

    DavidG

    46 posts

    I’m setting up a sermons list page for a church. They want to be able to sort the sermons by Bible book and chapter. I have a custom field for the Bible references. The problem is a typical sort looks like this:
    Psalm 1:2
    Psalm 110:1-3
    Psalm 2:1-5

    Obviously, EE is sorting everything numerically as it should. How can I get the sorting to sort by chapter correctly. I can’t very well add 0’s before the chapters without it looking odd. I don’t know if it’s a data entry issue or a different way to write the sorting code. Any help would be appreciated!  Here’s my code:

    {exp:weblog:entries orderby="sermontext" sort="asc" weblog="sermons" rdf="off"    }
     the results… 
    {/exp:weblog:entries}
  • #2 / Oct 30, 2007 7:05pm

    DavidG

    46 posts

    Any thoughts on this?

  • #3 / Nov 10, 2007 1:00pm

    Eric Snyder

    202 posts

    David:

    EE sorted based on text values - not numbers. I hope it’s something they will change (add a numerical field).

    There is an extension called REEOrder that works great but probably not appropriate for your needs. Search for REEOrder in the forums and you will find it.

    Custom code could be written but I have a simpler idea in mind.

    Use a text field for the sort. Assign each book, each chapter and each verse in the bible a number. When an entry is entered then enter a number based on the following rules. These rules could be programmed by someone with the right knowledge of EE and plugins and/or en tensions.

    Genesis = 00
    Exodus = 01
    ...
    Revelation = 66

    Chapters:
    0 (like Jude) = 00
    1 = 001
    2 = 002
    3 = 003
    etc

    Verse:
    1 = 001
    2 = 002
    etc.

    The following verses would look like this:

    Psalm 1:2         18001002
    Psalm 110:1-3     18110001  
    Psalm 2:1-5       18002001
    Relalation 5:10   66005010

    These would sort like this:

    Psalm 1:2         18001002
    Psalm 2:1-5       18002001
    Psalm 110:1-3     18110001  
    Relalation 5:10   66005010

    Set up your entries to sort on the field holding the above values and you would be all set. A note - it is important to understand that text sorts different than numbers in PHP so the fixed width numbers above with padded zeros is critical.

    Hope this helps.

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

ExpressionEngine News!

#eecms, #events, #releases