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.

How do I show only those entries beginning with A, B, C, etc.?

July 29, 2011 11:26am

Subscribe [4]
  • #1 / Jul 29, 2011 11:26am

    fanderson

    899 posts

    I have a site with several hundred entries. The client wants the option to display entries based on the first letter of the entry title.

    For example, the following page http://www.mysite.com/a/ would only display entries that begin with the letter A and so forth.

    Is there a way to do this in the channel tag? If so, how is it done?

    Thanks!

  • #2 / Jul 29, 2011 2:17pm

    Hi Forrest

    To achieve this you’ll have to dive in to some of the more advanced uses of Expression Engine. I recommend that you use the query module to achieve this, cause then you won’t have to enable PHP. Consider the following example:

    {exp:query paginate="top" sql="SELECT title,entry_date FROM exp_channel_titles WHERE title LIKE 'a%'"}
    
        {title} - {entry_date format="%Y %m %d"}
        
        {paginate}
        {if previous_page}
            <a href="http://{auto_path}">Previous Page</a>  
        {/if}
        {if next_page}
            <a href="http://{auto_path}">Next Page</a>
        {/if}
        {/paginate}
        
    {/exp:query}

    In the above example I use the LIKE parameter of the SQL query to let the database know that I only want rows(entries) where the title starts with ‘a’. If you want to show content from within custom fields as well then you will have to do another query to the exp_channel_data table 😊

    I hope this helps.

    /R

  • #3 / Jul 30, 2011 2:04pm

    Dan Decker

    7338 posts

    Hi Forrest,

    There is one third party add-on that might provide a solutuon as well, Low Alphabet.

    Rasmus, thanks for your suggestion! The SQL Module is also a fine solution and has the benefit of being free with ExpressionEngine.

    I’m going to move this into Community Help to continue the discussion.

    Best,

  • #4 / Aug 03, 2011 10:00am

    fanderson

    899 posts

    Hi Daniel,

    Yes, I agree that Low Alphabet is the best solution here. I put it in place and it works great! Highly recommended.

    Thanks,

    Forrest

  • #5 / Aug 05, 2011 4:29am

    driverweb

    15 posts

    This could be a feature request http://ellislab.com/forums/viewthread/194844/

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

ExpressionEngine News!

#eecms, #events, #releases