In
part two I said I was going to focus on the entries.tpl in this article. This is one of the least understood template files because most theme designers actually use the default entries layout and spend more time on the index.tpl or style.css files.
Whilst blog entries in Serendipity and Wordpress are similar, the way they are presented can be different. The first main difference is that Serendipity is a multi-user blog by default, which means our themes need to include a 'posted by' link to the author's name.
In addition, Serendipity event plugins often appear in the entry footer, for example the freetag, karma, or multilingual plugins. The dusk theme will require us to change our entries.tpl so that Rebecca's original format is followed.
Ok, as you might guess, I've already made the changes in my entries.tpl and the rest of this article will explain those changes. Please feel free to download the
updated dusk zipfile so that you can follow along.
I want to start with the entry title. The dusk theme uses an <h2> for the entry title, which is different from Serendipity where an <h3> or <h4> is usually used. In our header within the index.tpl we noticed that only one line was needed for the header, and it was an <h1> so changing our entry title to <h2> is not a problem.
The next line puts the date, time and categories directly underneath the entry title. This is different from Serendipity, where it usually sits underneath the entry. Also, Serendipity allows for sticky posts, and our date format includes the day of the week and is formatted for the 24 hour clock. I think our date and time formats are nicer so I'm not going to change these.
The dusk theme uses the class 'commentmeta', and Serendipity has no comparison, so we'll leave this in place.
The timestamp
<p class="commentmeta">
{$entry.timestamp|@formatTime:DATE_FORMAT_ENTRY}
{if not dategroup.is_sticky}
{$CONST.AT}
{entry.timestamp|@formatTime:'%H:%M'}
{/if}
The first line {$entry.timestamp|@formatTime:DATE_FORMAT_ENTRY} tells S9y to insert the entry's timestamp, ie the date it was published. However, rather than just spit out the default smarty timestamp format, use the format specified by our language file, and which is called DATE_FORMAT_ENTRY. Each language supported by Serendipity has its own language file within the lang folder. The date format is found in the first few lines.
The default Serendipity theme changes the word found between the date and time depending on whether the post is sticky or not sticky. Sticky posts get the word 'on', whereas the non sticky posts get the word 'at'. To try to be as faithful to the original dusk theme as I can I decided to remove that distinction, and make it so sticky posts have no time, whereas non sticky posts do get the time.
My next line asks if this is not a sticky post, then insert the word 'at' and the time the entry was published. If this is a sticky post then just exit the {if} statement without doing anything.
I would like to digress for a moment and mention any variable you find in any of the smarty template files. Any smarty code that begins with the word '$CONST.' such as {$CONST.ON}, {$CONST.EDIT_ENTRY} is a variable that simply tells Serendipity to use the word defined by the language file. So each of those two variables should be able to be translated into any language that s9y supports. Take a moment to open a language file and see for yourself!
Categories and edit entry
{if $entry.categories}
({foreach from=$entry.categories item="category" name="categories"}<a href="{$category.category_link}">{$category.category_name|@escape}</a>{if not $smarty.foreach.categories.last}, {/if}{/foreach}){/if}
</p>
The categories are another special case. Serendipity by default doesn't place brackets around the categories, so a little more smarty code was needed. My changes from the default theme are restricted to the
{if $entry.categories}( and
){/if}. Initially I thought simply placing the brackets around the <a href> would do the trick, but it turned out that this actually separated the categories with each having its own brackets and the dusk theme uses a single set of brackets around all categories.
Some of you might ask why I included the {if} statement, after all simply placing the brackets around the {foreach} would accomplish the same thing, and you are correct. However, I discovered that if an entry does not have any categories associated with it Serendipity would place a set of empty brackets into the post. This was not desirable, so the {if $entry.categories} asks the question is this entry associated with a category.
If you've used the dusk theme in Wordpress you would know that an 'uncategorised' category exists for WP users. I'm not sure how to deal with this for Serendipity, perhaps one of the programmers reading this post could make a comment?
Entry footer
The final task with our entries.tpl is to change the way our entry footer is handled. Since we didn't use the author link above, I decided to add this just before the comments link.
Also, the next tutorial in this series will cover comments, and the dusk theme handles comments and the entry footer link to comments differently. I've been experimenting and I believe it will be possible to change the way Serendipity handles these so that our dusk theme completely duplicates the way the WP dusk theme handles them. This will mean substantial changes to the entry footer smarty code so the next article in this series should be very exciting.