How can I order entries by title when each title is numeric? I originally asked this on Stack Overflow, but I'm hoping for more response here.

In Craft, I'm trying to order entries by the title. Each title is a number, but the sort function handles it like a string. Because of that 100 shows up before 2, 31 before 4, and so on.

{% for entry in craft.entries.section('mySection').order('title').find() %}
    &lt;h2&gt;§{{entry.title}}&lt;/h2&gt;
{% endfor %}


Is there a way to do this without extending  twig?
You can do that using MySQL’s cast() function:

craft.entries.section('mySection').order('cast(title as unsigned)')


Alternatively, you might get better performance if you create an actual Number field called “numberTitle”, attach it to your Entry Type, and set the Entry Type’s title to be dynamically generated using the template “{numberTitle}”. Then you can just order by that field instead:

craft.entries.section('mySection').order('numberTitle')