我猜你正在使用的SilverStripe Blog module 1.0 branch爲SilverStripe 3.1。
我無法在此循環中從博客條目運行任何方法,我只能運行博客持有者方法。
您應該可以調用BlogEntry
類中的所有BlogEntry
變量和函數。您不能從BlogHolder頁面調用BlogEntry_Controller
函數,但可以調用所有BlogEntry
變量和函數。
BlogEntry
有一個Author
文本變量在$db
所以你應該可以在你的博客條目循環中調用$Author
。
您可以使用博客模塊附帶的模板。這將顯示信息,如條目的作者,標籤,摘要,日期。
或者,如果您要創建自己的自定義模板,則可以查看現有模板作爲參考。
這是當前1.0分支博客持有者模板以及它如何通過條目循環。
BlogHolder.ss
<% include BlogSideBar %>
<div id="BlogContent" class="blogcontent typography">
<% include BreadCrumbs %>
<% if SelectedTag %>
<h3><% _t('BlogHolder_ss.VIEWINGTAGGED', 'Viewing entries tagged with') %> '$SelectedTag'</h3>
<% else_if SelectedDate %>
<h3><% _t('BlogHolder_ss.VIEWINGPOSTEDIN', 'Viewing entries posted in') %> $SelectedNiceDate</h3>
<% else_if SelectedAuthor %>
<h3><% _t('BlogHolder_ss.VIEWINGPOSTEDBY', 'Viewing entries posted by') %> $SelectedAuthor</h3>
<% end_if %>
<% if BlogEntries %>
<% loop BlogEntries %>
<% include BlogSummary %>
<% end_loop %>
<% else %>
<h2><% _t('BlogHolder_ss.NOENTRIES', 'There are no blog entries') %></h2>
<% end_if %>
<% include BlogPagination %>
</div>
在BlogEntries循環,它包括爲每個條目模板BlogSummary.ss。
BlogSummary.ss
<div class="blogSummary">
<h2 class="postTitle"><a href="$Link" title="<% _t('BlogSummary_ss.VIEWFULL', 'View full post titled -') %> '$Title'">$MenuTitle</a></h2>
<p class="authorDate"><% _t('BlogSummary_ss.POSTEDBY', 'Posted by') %> $Author.XML <% _t('BlogSummary_ss.POSTEDON', 'on') %> $Date.Long | <a href="$Link#comments-holder" title="View Comments Posted">$Comments.Count <% _t('BlogEntry_ss.COMMENTS', 'Comments') %></a></p>
<% if TagsCollection %>
<p class="tags">
<% _t('BlogSummary_ss.TAGS','Tags') %>:
<% loop TagsCollection %>
<a href="$Link" title="View all posts tagged '$Tag'" rel="tag">$Tag</a><% if not Last %>,<% end_if %>
<% end_loop %>
</p>
<% end_if %>
<% if BlogHolder.ShowFullEntry %>
$Content
<% else %>
<p>$Content.FirstParagraph(html)</p>
<% end_if %>
<p class="blogVitals">
<a href="$Link#comments-holder" class="comments" title="View Comments for this post">
$Comments.Count <% _t('BlogSummary_ss.SUMMARYCOMMENTS','comment(s)') %>
</a>
|
<a href="$Link" class="readmore" title="Read Full Post">
<% _t('BlogSummary_ss.READFULLPOST','Read the full post') %>
</a>
</p>
</div>
在BlogSummary你可以看到像$作者和$ Date.Long項目。
像這樣創建您的模板。您不需要在傳入條目ID的BlogHolder中調用一個函數。