x
 
Create New Page

Revision: Alphabetical Entries List

Revision from: 10:37, 6 Jan 2007

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 two 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>


<
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>
</
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>
</
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>
</
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>

<
h1>B</h1>

<
h1>C</h1>

<
h1>D</h1>

and so on for all the letters.

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.

The source thread on the ExpressionEngine Forum

Category:Tricks Category:Queries

Categories: