Keyword

Image captions on category list [IDEA]

  • Alfonso F. Moreno
  • Alfonso F. Moreno's Avatar Topic Author
  • Offline
  • Elite Member
More
13 years 6 months ago #94813 by Alfonso F. Moreno
Image captions on category list [IDEA] was created by Alfonso F. Moreno
This is a solution I have "developed" answering to a problem i had with captions of images in category lists. My site www.madridout.es is a newspaper so I needed to add captions to say for example: "The primer minister | Photo: Manuel". And also i needed to hide it if it was emmpty. So my solution is: At /components/com_k2/templates/default/category_item.php i added next line: <?php if(!empty($this->item->image_caption)): ?><p><?php echo $this->item->image_caption; ?> | <?php echo $this->item->image_credits; ?></p><?php endif; ?> just here (down the image but inside link <a> that all k2 category list images have): <?php if($this->item->params->get('catItemImage') && !empty($this->item->image)): ?> <!-- Item Image --> <div class="catItemImageBlock"> <span class="catItemImage"> <a href="/<?php echo $this->item->link; ?>" title="<?php if(!empty($this->item->image_caption)) echo $this->item->image_caption; else echo $this->item->title; ?>"> <img src="/<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->image_caption)) echo $this->item->image_caption; else echo $this->item->title; ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" /> <?php if(!empty($this->item->image_caption)): ?><p><?php echo $this->item->image_caption; ?> | <?php echo $this->item->image_credits; ?></p><?php endif; ?> </a> </span> <div class="clr"></div> </div> <?php endif; ?>

Then, changing CSS i gave same values creating a new class"span.catItemImage p" to make thar captions "float" over the image with a transparent background that i think is pretty: {text-align:left;margin:-20px 0 0 0;background: #b01111;color:#FFFFFF;font-size:11px;line-height:14px;opacity:0.8;padding:4px 0 4px 8px;width:402px;} Finally, I gave a limit to the number of words that can be inserted in the caption box in backend so the caption doesn't goes two lines instead one (breaking the effect)

 

Wait this help someone!!!!

(I have posted this in Spanish community in spanish, of course)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum