Vote Charlie!

Combining several Movable Type Entries blocks

Posted at age 24.
Created . Edited .

In certain cases, you cannot select all the Movable Type entries you might want to with a single Entries block.

You might have two custom fields for storing a color and a mood with each entry. Perhaps you then want to output entries that have a mood of either “happy” or “sad”, or any entries with a color of “green”.

The custom field modifier for the Entries block is not as flexible as it should be. It seems you can only specify one custom field to filter on, nor can you specify multiple values like you can with the “category” parameter.

You can get around this by employing a hash variable to gather all the entry IDs we are interested in, and then using a Loop block to sort them.

<mt:SetVarTemplate name="id_collector">
  <$mt:EntryID setvar="entry_id"$>
  <mt:SetVarBlock name="entry_ids{$entry_id}"><$mt:EntryDate format="%Y%m%d%H%M%S"$></mt:SetVarBlock>
</mt:SetVarTemplate>
<mt:Entries limit="20" field:mood="happy">
  <$mt:Var name="id_collector"$>
</mt:Entries>
<mt:Entries limit="20" field:mood="sad">
  <$mt:Var name="id_collector"$>
</mt:Entries>
<mt:Entries limit="20" field:color="green">
  <$mt:Var name="id_collector"$>
</mt:Entries>

<mt:Loop name="entry_ids" sort_by="value reverse">
<mt:Entries include_blogs="all" id="$__key__"><$mt:EntryID$> <$mt:EntryDate format="%Y%m%d%H%M%S"$></mt:Entries></mt:Loop>