Modifying MetaData for Entries

Aug 01, 2006 02:00

Hey all, the code below is a slightly modified and fully documented version of the function Entry::print_metadata. This function is responsible for printing the location, mood text and mood icon, music, and tags if applicable, below each entry. Note that while you could previously customize the label for each of these pieces of metadata, you could not do any of the following:
- reorder the elements (previously fixed to tags, location, mood, music)
- change the order of the mood text and mood icon (previous fixed to icon after text)
- remove the colons (:) after each label (previously it was "label: content")

Well now that's all changed. With this function, and by following the instructions, you can:
- reorder the elements (tags, location, mood, music) into any order
- change the order of the mood text and mood icon (you decide if icon comes before or after text)
- remove the colons (:) after each label (you can specify any separator you want, or none so you can do it in the customize wizard)

To use this function you must be a paid user and have a theme layer set up. Post the code at the end of your theme layer. Read through the instructions fully to understand what to change and how to change it. Note that if you have ever overridden this function before, this new function will supersede that old function as long as you place this at the end of your theme layer.


How to read the code:

- black : Regular code that you do not need to change at all. Please don't change it ... or you may break something.

- green : Explanatory comments. Read them. They let you know what changes you can make, and how to change them.

- red : Areas you can change. The green areas should have told you what they mean and how you can change them, so please don't go changing them randomly until you get what you want. That probably won't work.

Code:
## This function override allows users to change the order that the metadata elements print.
## To change the labels or whether the metadata print one per line or all on one line, users
## must still go through the Customization page and set properties accordingly.
function Entry::print_metadata() {

## If there is metadata (mood, music, location) or tags to print, and we're not in the guestbook, print stuff.
if (((size $.metadata>0) or ((size $.tags>0)and($*layout_position_entrytags=="metadata"))) and ($.itemid!=int($*layout_guestbook_entryid))) {

## Initialise the variables to print the metadata. Nothing prints here.
var string metaopen = "
    ";
    var string tags = "";
    var string location = "";
    var string mood = "";
    var string music = "";
    var string metaclose = "
";

## If you want the mood icon to print before the mood text, set the value below to false.
## Otherwise, a value of true will force the mood icon to print after the mood text.
var bool moodiconaftertext = true;

## If you want to change the separator after each metadata label, currently it is a colon (: ),
## change the colon in red to anything you would like. You should leave the space after
## the character you chose for formatting and visual appeal.
var string separator = ": ";

## Construct the tags if there are any, and if tags are set to print with metadata
if ((size $.tags>0)and($*layout_position_entrytags=="metadata")) {
$tags = "
  • $*text_meta_tags$separator $.tags[0].name";
    foreach var int i (1 .. (size $.tags - 1)) {
    $tags = $tags + ", $.tags[$i].name";
    }
    $tags = $tags + "
  • ";
    }

    ## Construct the location
    if ($.metadata{"location"}!="") {
    $location = "
  • $*text_meta_location$separator"+$.metadata{"location"}+"
  • ";
    }

    ## Construct the mood
    if ($.metadata{"mood"}!="") {
    $mood = "
  • $*text_meta_mood$separator";
    if (defined $.mood_icon and $moodiconaftertext) { $mood = $mood + $.metadata{"mood"}+" "+$.mood_icon; }
    elseif (defined $.mood_icon and not $moodiconaftertext) { $mood = $mood + $.mood_icon + " " + $.metadata{"mood"}; }
    else { $mood = $mood + $.metadata{"mood"}; }
    $mood = $mood + "
  • ";
    }

    ## Construct the music
    if ($.metadata{"music"}!="") {
    $music = "
  • $*text_meta_music$separator"+$.metadata{"music"}+"
  • ";
    }

    ## Print the elements in the specificed order. You may change the order
    ## they print by rearranging the order of the variables in red. However,
    ## $metaopen must be first and $metaclose must be last!!
    print $metaopen + $tags + $location + $mood + $music + $metaclose;

    }
    }

    metadata, mood icon, tutorial

    Previous post Next post
    Up