S
S
Sergey Defactov2017-01-12 16:14:56
Yii
Sergey Defactov, 2017-01-12 16:14:56

Displaying the image of the news on the main page?

Cms Open real Estate
in the News List displays an image and a preview of the description, but only the title and date are displayed on the main page
how to display the image and description on the main
page Code from index.php

<?php if (isset($entriesIndex) && $entriesIndex) : ?>
  <div class="clear"></div>
  <div class="last-entries-index">
    <p class="title"><?php echo tt('News', 'entries');?></p>
    <?php foreach($entriesIndex as $entries) : ?>
    
      <div class="last-entries-item">
        <div class="last-entries-date">
          <p class="ns-label">
            <?php echo $entries->dateCreatedLong;?>
            
            
          </p>
        </div>
        
        <div class="last-entries-title">
          <?php echo CHtml::link(truncateText($entries->getStrByLang('title'), 80), $entries->getUrl());?>
        
        </div>
      </div>
    <?php endforeach;?>

Widget Code
<?php
foreach ($entries as $item) : ?>
    <div class="entries-items">
     

    <?php if($item->image):?>
      <div class="imagenews"><?php $src = $item->image->getFullThumbLink(); ?>
      <?php if($src) : ?>
        <div class="entries-image-list">
          <?php
          $tagAlt = CHtml::encode($item->getStrByLang('title')); 
          if (issetModule('seo') && isset($item->image->image_seo) && $item->image->image_seo->getStrByLang('alt')) {
            $tagAlt = CHtml::encode($item->image->image_seo->getStrByLang('alt'));
          }
          ?>
          <?php echo CHtml::link(CHtml::image($src, $tagAlt), array('class' => 'sxa')); ?>
        </div>
      <?php endif; ?>
    <?php endif; ?>

    <p>
      <span class="title"><?php echo CHtml::link(CHtml::encode($item->getStrByLang('title')), $item->getUrl()); ?></span>
    </p>
    <?php
      echo $item->getAnnounce();
    ?></div>
        <p>
        </p>
        <div class="clear">
    </div>
<?php endforeach; ?>

<?php

if(!$entries){
  echo tt('Entries list is empty.', 'entries');
}

if($pages){
  $this->widget('itemPaginator',array('pages' => $pages, 'header' => ''));
}
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-01-12
@cashloveyou

should output if $item->image exists, and why it is not there - you need to look in the model or in the controller, unless of course the widget is used, judging by the code in the index - this is not so
You can try to replace in index:

<div class="last-entries-title">
          <?php echo CHtml::link(truncateText($entries->getStrByLang('title'), 80), $entries->getUrl());?>
        
        </div>

on this:
<div class="last-entries-title">
          <p><?php echo CHtml::link(truncateText($entries->getStrByLang('title'), 80), $entries->getUrl());?></p>
    <?php if($entries->image):?>
      <div class="imagenews"><?php $src = $entries->image->getFullThumbLink(); ?>
      <?php if($src) : ?>
        <div class="entries-image-list">
          <?php
          $tagAlt = CHtml::encode($entries->getStrByLang('title')); 
          if (issetModule('seo') && isset($entries->image->image_seo) && $entries->image->image_seo->getStrByLang('alt')) {
            $tagAlt = CHtml::encode($entries->image->image_seo->getStrByLang('alt'));
          }
          ?>
          <?php echo CHtml::link(CHtml::image($src, $tagAlt), array('class' => 'sxa')); ?>
        </div>
      <?php endif; ?>
    <?php endif; ?>
        
        </div>

but this is a finger to the sky according to your fragmentary data.

S
Sergei Defactov, 2017-01-12
@cashloveyou Asker

displayed the image but it is hidden, if you set position absolute in force, it shows

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question