Advanced Advanced Indexes
Date: 12-05-2007 15:54 Views: 6249
Why are they called Advanced Indexes?
In the original production versions of MonkeyCMS there were a number of independent index functions - these were both basic in their functionality and complex in their implementation. These indexes are still available within MonkeyCMS for compatibility reasons, but there are no functional or technical reasons for their use. Advanced Indexes are the comprehensive replacement and allow you to do far more through a simple interface.
This tutorial will cover different functionality available with Advanced Indexes and how to tap their full potential. It will not tell you how to include them in your templates - although you can learn how to do this in the advancedindex function documentation and the Building Custom Index Pages tutorial.
Basic Advanced Indexes
At a basic level, Advanced Indexes display a list of content based on your specifications - you can have one or more definitions, order them by any of the main content fields and filter using basic MySQL where clauses. This is all reasonably straightforward.
To create an Advanced Index, browse to the Skin Manager - Layout > Skin Manager. Select the skin you would like to modify (it is recommended you work on either a child skin of the Default, or on a copy as any changes you make may be overwritten with MonkeyCMS upgrades). Once you have selected your skin, you'll be able to see Advanced Indexes listed on the left hand side.
Carrying on our example Book website, we'll create a basic index for Book Reviews, so click the Add Index link.
In the Editor pane, you'll be shown a blank Advanced Index form. Populate it as follows:
Using the Where Clause
There may be instances where you only wish to display reviews of a certain type. In an earlier tutorial we created three content types for the Review definition - Fiction, Non-Fiction and Reference. Let's create an index to display the latest Non-Fiction reviews...
Browse to the Skin Manager for your modified skin and click Add Index. Name the index 'NonFictionBookReviews' and select the Review definition. We'll again order by descending date to display the latest reviews. In the Where Clause field, we need to specify to show only the Non-Fiction reviews - and the content type is stored within the 'contenttype' field in the database. Therefore, the Where Clause will be contenttype='Non-Fiction'.
What fields can I usein my Where Clause?
You can use the following fields in your Where Clause:
There may be times when you want to influence your indexes by passing in parameters - maybe you want an index to filter results alphabetically or have one index to cater for all content types. This is reasonably straightforward as you are able to pass parameters to your indexes via the Query String.
For an example you could pass in a letter to filter on with the following URL:
To use these parameters in your index, you must let MonkeyCMS know to expect them.
Create a new Index called BookReviewsAlpha and set the definition to Review. Choose to order by index_title ascending.
In the Parameters field, enter letter. You can then access the parameter in your Where Clause by enclosing it in square parenthesis (). The appropriate Where Clause in this instance would be index_title like '[letter]%' - this means that all reviews starting with the letter supplied will be displayed.
All you then need is to include the appropriate links on your site which supply the parameters to the Query String.