wide_widget.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. $topic_id = 136;//Переговорка
  3. $topic = \app\models\base\NewsTopic::findOne(['id'=>$topic_id]);
  4. /**
  5. * @var $post \app\models\News
  6. */
  7. $post = Yii::$app->cache->getOrSet("main-page-wide-widget",function () use($topic_id){
  8. return \app\models\News::find()
  9. ->alias('n')
  10. ->joinWith('topics')
  11. ->with('commentsAll')
  12. ->andWhere(['news_topic.id'=>$topic_id])
  13. ->orderBy(['dt_pub'=>SORT_DESC])
  14. ->one();
  15. },600);
  16. ?>
  17. <div class="wide-widget row">
  18. <div class="col-md-8">
  19. <div class="cont">
  20. <?php if($post->image instanceof \app\models\base\Image):?>
  21. <div class="picture-cont-16x9">
  22. <picture class="w-100">
  23. <source srcset="<?=$post->image->url?>" media="(min-width: 600px)">
  24. <img src="<?=$post->image->url?>" alt="<?=$post->photo_title?>" class="w-100" loading="lazy">
  25. </picture>
  26. </div>
  27. <?php endif;?>
  28. <div class="meta">
  29. <h2 class="title">
  30. <a href="<?=$post->url?>"><?=$post->title?></a>
  31. </h2>
  32. <div class="topic">
  33. <?=$topic->title?>
  34. </div>
  35. <?php
  36. $comments = $post->commentsAll;
  37. if(!is_null($comments)){
  38. $count=count($comments);
  39. } else{
  40. $count = 0;
  41. }
  42. ?>
  43. <?php if($count>0 || 1):?>
  44. <div class="commnets">&nbsp;<svg class="icon icon-comments"><use xlink:href="/svg/symbol/sprite-clear.svg#comments"></use></svg><?=$count?></div>
  45. <?php endif;?>
  46. </div>
  47. </div>
  48. </div>
  49. <div class="adv col-md-4">
  50. <div class="cont">
  51. </div>
  52. </div>
  53. </div>