x
 
Create New Page
 View Previous Changes    ( Last updated by Digitaal Dier )

Alphabetical Entries List

Table of Contents


Creating a full list of entries divided by the entries titles’ first letters

Extension

smallbeer put together an extension to do this.

There are three other ways of doing this list.

First Method

Create a template which should serve your list.

Insert the following code into this template:

<ul
{exp:query sql="SELECT title, entry_id, url_title AS urlt 
FROM exp_weblog_titles WHERE weblog_id = '1' 
AND title LIKE 'A%' ORDER BY title ASC"

<li>{title}</li
{/exp:query}
</ul


<
ul
{exp:query sql="SELECT title, entry_id, url_title AS urlt 
FROM exp_weblog_titles WHERE weblog_id = '1' 
AND title LIKE 'B%' ORDER BY title ASC"

<li>{title}</li
{/exp:query}
</ul

and so on for all the letters you need.

Here weblog_id is your weblog’s id (you can check it in the Control Panel: Admin -> Weblog Preferences) and A% is the letter you need, assuming that all your entries start with a capital letters.

You can make the entries titles to be links to those entries:

<ul
{exp:query sql="SELECT title, entry_id, url_title AS urlt 
FROM exp_weblog_titles WHERE weblog_id = '1' 
AND title LIKE 'A%' ORDER BY title ASC"

<li><a href="{path=weblog/entry}{urlt}/">{title}</li
{/exp:query}
</ul

Where weblog/entry is your Template_Group/Template for a single entry.

Second Method

First, create a new template group (say, ‘letters’)

Into this template insert the following code

<ul
{exp:query sql="SELECT title, entry_id, url_title AS urlt 
FROM exp_weblog_titles WHERE weblog_id = '1' 
AND title LIKE '{segment_3}%' ORDER BY title ASC"

<li><a href="{path=weblog/entry}{urlt}/">{title}</li
{/exp:query}
</ul

Where weblog/entry is a link to your Template_Group/Template for a single entry.

Second, create a new template which will handle the whole list, say, ‘List’

Put the following code into this template where you want the list to appear:

<h1>A</h1
[embed="weblog/letters/a"]
<h1>B</h1
[embed="weblog/letters/b"
<h1>C</h1
[embed="weblog/letters/c"]
<h1>D</h1
[embed="weblog/letters/d"

and so on for all the letters. Replace { with [ of course.

Here weblog/letters is your template_group/template created on the previous step.

You can change

<h1></h1

to the needed header or paragraph selector.

Third method

Create a template which should serve your list.

This method extends the first, but relies on php being enabled for the template that you want the alphabetical list to show on.

Insert the following code into this template:

<?php foreach(range('A','Z') as $alphabet){ ?>

    
<h3><?php echo $alphabet;?></h3>
    <
ul>
    
{exp:query sql="SELECT title, entry_id, url_title AS urlt FROM exp_weblog_titles WHERE weblog_id = '1' AND title LIKE '<?php echo $alphabet;?>%' ORDER BY title ASC"}
    
<li><a href="{path=group/template}{urlt}/">{title}</a></li>
    
{/exp:query}
    
</ul>

<?php } ?> 

In ExpressionEngine 2.1

I’ve updated the code for EE2.1. You’ll need to set “Allow PHP” to “Yes” and “PHP Parsing Stage” to “Input”.

<?php foreach(range('A','Z') as $alphabet){ ?>
        
<h3><?php echo $alphabet;?></h3>
        <
ul>
        
{exp:query sql="SELECT title, entry_id, url_title AS urlt FROM exp_channel_titles WHERE channel_id = '4' AND title LIKE '<?php echo $alphabet;?>%' ORDER BY title ASC"}
            
<li><a href="{path=group/template}/{urlt}">{title}</a></li>
        
{/exp:query}
        
</ul>
        
<?php } ?> 

Category:Tricks Category:Queries

Category:EE1 Category:EE2

Categories: