-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from pafnuty/4.9.1
Добавлен пример с выводом комментариев к каждой новости в блоке
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{* | ||
Условие, которое отобразит информацию о корректном вызове этого шаблона, если такое не произошло. | ||
Например когда в строке подключения указан этот шаблон | ||
*} | ||
{if $postId > 0} | ||
|
||
{* | ||
Определяем сколько комментариев получить. | ||
Если передан параметр limit и он больше нуля, позьмём его | ||
Если нет - поставим 10. | ||
*} | ||
{set $commentsLimit = ($limit > 0) ? $limit*1 : 10 } | ||
|
||
{* | ||
Получаем комментарии прямым запросом в БД, через класс SafeMySQL | ||
http://phpfaq.ru/safemysql | ||
*} | ||
|
||
{set $comments = $.blockPro->db->getAll('SELECT * FROM ?n WHERE post_id=?i LIMIT 0, ?p', 'dle_comments', $postId, $commentsLimit)} | ||
|
||
{* Пробегаем по полученным комментариям *} | ||
{foreach $comments as $comment} | ||
<p> | ||
Автор: <b>{$comment.autor}</b> | {$comment.date|dateformat} | ||
</p> | ||
<p> | ||
{$comment.text} | ||
</p> | ||
{foreachelse} | ||
<p>Комментариев у новости нет</p> | ||
{/foreach} | ||
{else} | ||
<div class="alert"> | ||
Этот шаблон следует вызывать подключать внутри цикла, используя такую конструкцию: | ||
<pre>{ignore}{include '/blockpro/bp_comments.tpl' postId=$el.id limit=5}{/ignore}</pre> | ||
</div> | ||
{/if} |