Porting Templates |
出自LifeType 中文文件計畫
目錄 |
移植模版到 LifeType 1.1
針對LifeType 1.0 設計的模版,在沒有移植的情況下,也可以正常的在LifeType 1.1版中使用。但是它可能無法使用最新的功能,例如:分頁功能。
下面的內容將提供餒對移植模版感興趣的使用者做為參考,說明在模版移值的過程中,那些是在模版檔案中所必需做的修改。
文章分頁
LifeType 1.1會依據整個部落格、某個月份的匯整或是某個目錄下的文章數目,自動在首頁產生分頁。但是,我們必需使用一些額外的Smarty語法來顯示分頁。
顯示分頁最簡單的方式是將檔案misc/pager.template引用進來,該檔案已經包含所有顯示分頁必需的邏輯內容。
你可以在main.template 或 footer.template的最底部(分頁顯示的確切位置,可能會依照模版的不同而有所差別)加入以下程式碼:
{include file="misc/pager.template" style="links"}
style 後的參數值可以使用下面的任何值來取代:
- links will display a basic horizontal list of links, with a "Next" and "Prev" links which appear or not depending on the current page and the number of pages.
- forwardonly will only display the forward link, but only if it is necessary.
- backonly will only display the link to the previous page, but only if it is necessary (i.e. will not appear if we are at the first page of the list)
The following CSS classes are available for the pager:
- pagerLink: used for any of the links in the pager.
- pagerLinkPrevPage: used for the "Prev" link.
- pagerLinkNextPage: used for the "Next" link.
- pagerCurrent: used for the current page, which will not be linked.
Usually it will enough to add the Smarty code listed above and make sure that the pager fits with the overall design of the page. In cases where further customization is needed, it is possible to use the different available styles and even create our own custom pager.
檔案分頁
As with articles, resources are also displayed in a paged fashion since LifeType 1.1.
Unlike with articles, it is necessary to make an additional change to our template in order to get a paged display of resources. If these changes are not made, we will get the normal non-paged display of resources where all of them are displayed in one single page.
In album.template find the following Smarty code:
{assign var=resources value=$album->getResources()} {foreach from=$resources item=resource}
And replace it with the following:
{foreach from=$resources item=resource}
The difference in this case is tha the $resources array has already been preset wtih only the resources that should be displayed in this page, while the previous version will load all the resources in the album. From a performance point of view, it is also a better solution.
Now in order to get the pager displayed, we have to apply the same solution that was applied for paged posts via misc/pager.template. The pager works in exactly the same way regardless of whether it is being used to page posts or resources so no extra changes are required.
Somewhere in album.template, we will have a line like this:
{include file="misc/pager.template" style="links"}
The location of the pager will depend on the current style of our page.
取得迴響和引用的正確數字
Up to version 1.0 of LifeType, the call $post->getNumComments() returned the number of non-spam comments while $post->getTotalTrackbacks() returned the number of non-spam trackbacks. For consistency reasons, LifeType 1.1 fixes this issue and now the methods have been fixed:
- $post->getTotalComments(): returns the number of non-spam comments.
- $post->getTotalTrackbacks(): returns the number of non-spam trackbacks.
- $post->getNumComments(): returns the total number of comments (both spam and non-spam)
- $post->getNumTrackbacks(): returns the total number of trackbacks (both spam and non-spam)
When porting templates from LifeType 1.0.x to LifeType 1.1, please remember to replace all occurrences of getNumComments() with getTotalcomments() or else the comment counters will show confusing values.