我猜你正在使用 SilverStripe Blog module 1.0 branch 用于 SilverStripe 3.1。
我无法在此循环中运行博客条目中的任何方法,我只能运行博客持有者方法。
您应该能够调用BlogEntry 类中的所有BlogEntry 变量和函数。您不能从 BlogHolder 页面调用 BlogEntry_Controller 函数,但可以调用所有 BlogEntry 变量和函数。
BlogEntry 在$db 中有一个Author 文本变量,因此您应该能够从您的博客条目循环中调用$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 中,您可以看到 $Author 和 $Date.Long 等项目。
像这样创建您的模板。您不需要调用 BlogHolder 中的函数并传入条目 ID。