EllisLab text mark
Advanced Search
1 of 2
1
   
Sort Entries Alphabetically, Group By Letter
Posted: 03 June 2008 03:49 PM   [ Ignore ]
Joined: 2007-05-16
27 posts

I’d like to return a list of entries grouped by letter, with the ability to wrap the letter header (e.g. “A”) in a different tag than the entries. Example:

A
Apple
Artichoke

B
Ball
Bible
Brian

And so on…

I found a plugin that can do this, but it is not well documented and some of the parameters have to be hard coded into the plugin. Is it possible to do this without a plugin?


Brian Morykon

 
Posted: 03 June 2008 04:49 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2004-05-15
29075 posts

There is no native solution that I am aware of, so the atozee plugin is probably your best choice. There is some more info in the wiki.

Moving to Howto.

 
Posted: 03 June 2008 05:01 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-05
1431 posts

I want something similar, but I all I need to do is sort the entry title by alphabetically.  I’ll just make exp:weblog:entries for each letter.

I dont see the atozee plug-in on the addon-page.  Can you direct us?

 Signature 

Marshall Grant   |  grantmx.com  |  Atlanta, GA   |  design  |  development  |  @grantmx

 
Posted: 03 June 2008 05:11 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2004-05-15
29075 posts

grantmx, keystone linked to the relevant forum thread in his post.

 
Posted: 03 June 2008 05:15 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-05
1431 posts

Thanks Ingmar cheese

 Signature 

Marshall Grant   |  grantmx.com  |  Atlanta, GA   |  design  |  development  |  @grantmx

 
Posted: 03 June 2008 05:18 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2004-05-15
29075 posts

No worries, and good luck smile

 
Posted: 03 June 2008 05:37 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2008-01-27
140 posts

i sort live music venues and bands by alphetical letter (like if you want to see all bands with names starting with the letter B) using a template that sorts alphabetically. then, i made a category group to share amongst all of my weblogs called “alphabetical” where a category is held for each letter in the alphabet (each letter has a category_id). it’s handy and can be used across multiple weblogs to sort in just about any template if the subject matter can be alphabetized meaningfully.

 Signature 

Rökker
Vodkatuer
http://www.rokkervodka.com

 
Posted: 03 June 2008 05:43 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-05
1431 posts

I don’t remember, but is it possible to use exp:query in conjunction with exp:weblog:entires to pull custom field data from each entry?

 Signature 

Marshall Grant   |  grantmx.com  |  Atlanta, GA   |  design  |  development  |  @grantmx

 
Posted: 03 June 2008 05:51 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-05
1431 posts

Never mind.  Yes.

 Signature 

Marshall Grant   |  grantmx.com  |  Atlanta, GA   |  design  |  development  |  @grantmx

 
Posted: 10 July 2008 04:19 AM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2007-01-05
1427 posts

I am trying to create groups of links broken down by the first letter.

So -

A
Apple
Amsterdam
Aluminium
Abracadabra

B
Burger
Black
Banter

Etc.

The second thing is not to show anything if there are no entries beginning with that letter.

I tried to adapt Ray’s SQL but I am a bit lost -

<?php
global $DB;
$gletter='_';
$x '';
    for (
$i=65$i<=90$i++) // For lowercase letters, use the numbers 97-122 instead
        
$x chr($i);
      if (
$gletter<>substr($x,0,1)) {
              $gletter
=substr($x,0,1);
                    
$results $DB->query("SELECT COUNT(*) as number FROM exp_weblog_titles WHERE weblog_id = 2 AND title LIKE '$gletter%' LIMIT 1;");
                    
$count $results->row['number'];
                         if (
$count 0{
                                
echo '{exp:weblog:entries weblog="artists" orderby="title|artists_first_names" sort="asc"}
                <div class="ddmcc">
                    <ul>
                        <p class="sep">'
.$gletter.'</p>
                        <ul>
                            <li><a href="{url_title_path=">{title}, {artists_first_names}</a></li>
                        </ul>
                    </ul>
                </div> <!-- ddmcc -->
                {/exp:weblog:entries}'
;
                        
else {
                                
echo '<li>'.$gletter.'</li>';
                        
}
                                    
            }
                    
    }
?> 

But this just spits out all the entries each time a first letter is matched with any of the entries.

 Signature 

Steven Hambleton | Hambo Development

WE SPECIALISE IN WORKING WITH AGENCIES AND BUILDING LONG TERM DEVELOPMENT PARTNERSHIPS 
 
Posted: 10 July 2008 08:29 AM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2002-02-05
462 posts

Hi Steve,

The simplest solution I came up with is this one:

<?php $temp ''?>

{exp
:weblog:entries weblog="your_weblog" orderby="title" sort="asc"}

<?php
$letter 
strtoupper(substr('{title}'01));
if (
$temp != $letter{
    
echo "<h3>" $letter "</h3>";
    
$temp $letter;
}
?>

<p>{title}</p>

{/exp:weblog:entries} 

PHP on output.

 
Posted: 19 December 2008 02:41 PM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2006-07-31
65 posts

How can this still script be adapted to select a particular letter of alphabet or character?

 
Posted: 27 March 2009 05:04 AM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Joined: 2009-02-09
20 posts

Thanks, Cocoaholic, your code works like a charm.

 
Posted: 26 April 2010 01:40 PM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2007-05-15
433 posts

Another thanks to Cocoaholic, that code just worked great for me too!

I was even able to adapt it slightly to output a list of anchors too:

{exp:weblog:entries weblog="my_weblog" orderby="title" sort="asc" dynamic="off"}
<?php
$letter 
strtoupper(substr('{title}'01));
if (
$temp != $letter{
    
echo "<a >".$letter."</a>";
    
$temp $letter;
}
?>
{
/exp:weblog:entries} 

To perfect it, I might try and adapt this further so that letters of the alphabet with no entries on the page still appear, but without the anchor links, but I’ll see if my client is happy without this first. smile

Thanks.

 Signature 

 
Stephen McIver | Made by Bridge | Huddersfield & Liverpool, UK | Twitter

 
Posted: 29 June 2010 07:34 AM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Joined: 2006-11-02
228 posts

This works a treat. Thanks to Cocoaholic and sm9. And since I am building a glossary, my tweaked code incorporates definition lists…

<?php $temp ''?>

{
!-- output a linked list of the letters represented with each letter as an href --}
<p id="a-z">
Skip to terms beginning with
{exp:weblog:entries weblog="glossary" orderby="title" sort="asc"}
<?php
$letter 
strtoupper(substr('{title}'01));
if (
$temp != $letter{
    
echo '<a href="#'.$letter.'" rel="self">'.$letter.'</a></li>';
    
$temp $letter;
}
?>
{
/exp:weblog:entries}
</p>

{!-- output a linked list of the terms covered to show/hide with jQuery --}
<div id="terms">
<
class="preamble">We have definitions for: </p>
<
ol>
{exp:weblog:entries weblog="glossary" orderby="title" sort="asc"}
<li><a href="#{url_title}" rel="self">{title}</a></li>
{/exp:weblog:entries}
</ol>
</
div>

{!-- output the definitions --}
{exp
:weblog:entries weblog="glossary" orderby="title" sort="asc"}
<?php
$letter 
strtoupper(substr('{title}'01));
if (
$temp != $letter{
    
// set id to the current letter as destination for the a-z list links
    
echo '<h2 id="'.$letter.'">'.$letter.'</h2>';
    
$temp $letter;
}
?>
{
!-- set id to the url title as destination for the list of terms links --}
<dl><dt id="{url_title}">{title}</dt>
<
dd>{body}</dd></dl>

{/exp:weblog:entries} 
 
Posted: 06 July 2010 01:41 AM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2009-09-20
526 posts

Correct me if I’m wrong, but doesn’t this code pull every single entry, and then just display the relevant ones? WOuldn’t add a lot of overhead with thousands of records? Surely a query that only pulls the required entries each time would be a lot more efficient?

Really wish you could just do something like search:title=“A*” in the channel entries tag!

 Signature 

Exp:resso  - the ExpressionEngine Wizards
Developers of Exp:resso Store - intelligent, powerful e-commerce

 
1 of 2
1