Blog Master G

Word. And photos, too.

Blog Master G random header image

Category Subset Template

Friday, January 23rd, 2004 · 2 Comments

The Objective: Create a page that displays the full text of entries X, Y, and Z, which are a subset of category A.

The Problem: Existing category display templates are designed to show only a listing of contents with links to individual posts. Additionally, the need is to display a subset of the category and not the entire category.

The Solution: Create a new index template, specify an output file, copy the template contents of a template that does display full text from each entry (like monthly archives do in my blog). Next, leverage Brad Choate’s excellent MTSQL plugin by inserting the following code (tweaked however you need) in place of the <MTEntries> tag:

    <MTSQLEntries query=”select entry_id from mt_entry
    where entry_title like ‘%Cross Country%'”>

Voila! That’s it. Use the existing code to display the entries as you’d like.

The Result: Cross Country 2003. This page contains the full body of all entries whose titles contain the text “Cross Country.” Note that these entries are all categorized in my relocating category, but now I have a custom page only for those entries relating to my cross-country trip. Also note that this implementation is far more flexible than using only entry titles; you could create a custom page with specific entry IDs, post dates, etc. MTSQL allows you to build a query leveraging any of your data in the MT database.

Tags: site features

2 responses so far ↓

  • 1 Jordan // Jan 23, 2004 at 1:47 pm

    Is it sad that my first reaction to that is the fact you’re going to do a full-table-scan to execute that query? Followed by thinking of optimization techniques… followed by the realization that I have actual work to do and that I don’t care. Yes. Yes it is…

  • 2 gabe // Jan 24, 2004 at 10:10 am

    Good point. Perhaps it would be better simply to select the entries directly by their IDs to avoid doing a full table scan. That was actually my original plan, then I took the easy route.