temalenta.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. use app\models\front\News;
  3. use yii\data\ActiveDataProvider;
  4. $items = (isset($items) && $items > 0)?$items:50;
  5. if( isset($topic) && $topic ){
  6. $news_query = \app\models\front\News::find()->leftJoin('news_topic_relation t', 't.news_id = id')->andWhere(['t.topic_id'=>$topic]);
  7. $newsDataProvider = new ActiveDataProvider([
  8. "query"=>$news_query,
  9. 'sort'=> [
  10. 'defaultOrder' => ['dt_pub' => SORT_DESC],
  11. ],
  12. "pagination" =>[
  13. "pageSize"=>$items
  14. ],
  15. ]);
  16. ?>
  17. <a class="news-link" href="/news">Лента новостей</a>
  18. <div class="lenta">
  19. <?= Yii::$app->cache->getOrSet("topics_page_lenta_".$topic,function () use ($newsDataProvider){
  20. return \yii\widgets\ListView::widget([
  21. "dataProvider"=>$newsDataProvider,
  22. 'options' => [
  23. 'tag' => 'div',
  24. 'class' => 'list-wrapper',
  25. 'id' => 'list-wrapper',
  26. ],
  27. "layout" => "{items}",
  28. "itemView"=> "/layouts/lenta/_item"
  29. ]);
  30. },120);
  31. ?>
  32. <div class="all-news">
  33. <a href="/news">Все новости</a>
  34. </div>
  35. </div>
  36. <?
  37. }