Modifying the Date/Subject bar for Entries

Aug 01, 2006 01:04

Hey all, the code below is a slightly modified and fully documented version of the function Entry::lay_print_subjectline. This function is responsible for printing the Date/Subject bar on all entries, and by default had the following format: date_time - security_icon subject [tags_list]. Note that while you could customize the format of the date and time, and change the tags to appear in the metadata, you could not do any of the following:
- reorder the elements on the line
- change the dash
- change the square brackets around the tags list
- change the security icons away from the livejournal default grey lock and eye symbols

Well now that's all changed. With this function, and by tweaking it, you can get the subject bar to display exactly how you want (ie. in any order of elements), and you can even define custom security icons!

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:
function Entry::lay_print_subjectline(Color bg, Color fg, bool usecolour) {
var Page p = get_page();

## Set up variables which will hold html for each portion of the subject/date line.
## The only thing you can change here is the separator between the date and subject
## which is by default a dash (-). If you would like to change it to another character,
## simply change the dash in red on the next line to another character, or none.
## However, at minimum you should leave a single space since no space is provided elsewhere.
var string separator = (defined $.security_icon or $.subject!=""?" - ":"");

var string headeropen = "";
var string date = "";
var string securityicon = (defined $.security_icon?""+$.security_icon:"");
var string subject = "";
var string tagslist = "";
var string headerclose = "";

## If you would like to assign custom security icons, decomment the
## two lines below by removing the # from in front of it, and changing the
## portions of each line in red with the appropriate image heights, widths,
## urls, and if you desire, the alternate text. You must define these values
## properly for the images to show up.
# if ($.security=="protected") { $securityicon = "
HH width=WW src='http://yourdomain.com/yourlock.gif' alt='[protected]' />"; }
# if ($.security=="private") { $securityicon = "
HH width=WW src='http://yourdomain.com/yourprivate.gif' alt='[private]' />"; }

## if the post being printed is not the guestbook post, print all information.
if ($.itemid!=int($*layout_guestbook_entryid)) {

## Construct the opening div tag for the header, with friends colors if applicable
$headeropen = $headeropen + "
";

## Construct the date portion using the appropriate format from the properties
$date = $date + "";
if ($p.view!="day") {
$date = $date + $.time->time_format($*text_format_entry_date_and_time);
}else{
$date = $date + $.time->time_format($*text_format_entry_time);
}
$date = $date + "";

## Construct the subject portion of the header
$subject = $subject + "" + ($p.view=="entry"?"":$.subject) + "";

## Construct the tags portion of the header. It will be of the form: [tag1, tag2, tag3]
## If you would like to change the brakets or the separator, you may do so by changing
## the values in red below with whatever character you would like. Please note
## that the values below contain spaces which should be preserved to help formatting the line.
if ((size $.tags>0)and($*layout_position_entrytags=="subject")) {
var string tagslistopenbracket = " [";
var string tagslistclosebracket = "] ";
var string tagslistseparator = ", ";
$tagslist = $tagslist + "$tagslistopenbracket $.tags[0].name";
foreach var int i (1 .. (size $.tags - 1)) {
$tagslist = $tagslist + $tagslistseparator + " $.tags[$i].name";
}
"$tagslistclosebracket";
}

## Print the header area in order. If you would to change the order the elements appear
## in the subject/date line, then alter the order the variables in red appear below.
## Important: $headeropen must come first, and $headerclose must come last.
print $headeropen + $date + $separator + $securityicon + $subject + $tagslist + $headerclose;
## An inactive example to show how to put the date after the subject:
# print $headeropen + $securityicon + $subject + $separator + $date + $tagslist + $headerclose;

## if the post being printed is the guestbook post, then only show the security icon (if it exists)
}else{
"""
$securityicon""";
}
}

security icons, subject bar, tutorial

Previous post Next post
Up