display no image if doesnt exist codeigniter - codeigniter

All i want to do is display an image if the image exist if not display blank but i cant seem to figue it out.
Im storing my image path file in my database, in the column called, file and path is stored like this:
/images/file_name
now if there isnt an image being posted it stores /images/
if ($news_item['file'] = '/images/11.jpg') { ?>
<img src="<?php echo base_url(); echo $news_item['file'] ?>">
} else {
echo '';
}
?>
If you need anything more of me let me know but just to give you an idea of what I'm achieving.
its a news post, if you create a post you have a title and description and you have the choice of entering in a file/image.. if you leave it blank it will enter in /images/ and if you enter an image in it will be: /images/file_name (this is inserted into a db)

Check like this:
if (file_exists($news_item['file'])) {

I would simply use the alt property of the image to show an alternative text:
<img src="<?php echo base_url(); echo $news_item['file'] ?>" alt="no image">
or, if you want it to be completely blank:
<img src="<?php echo base_url(); echo $news_item['file'] ?>" alt="">
EDIT:
To completely remove the image, you can conditionally generate the image or an alternative text:
if (file_exists($news_item['file'])) {
echo '<img src="'.base_url().$news_item['file'].'">';
} else {
echo "No image";
}

I suggest you to store the default.jpg in DB ( You can set this default in DB ). And store the default.jpg image in image folder. So that you don't need to change anything in coding.

Related

how to get skin url [attr()] from js file in magento

For example on hover I want to change small image to thumbnail is it possible please don't say to change any code on list.phtml
$j('.foo').hover(function(){
$j(this).attr('src','<?php echo $this->helper(catalog/image)->init($_product, thumbnail) ?>');
});
try that..
<?php Mage::getModel('catalog/product')->load($_product->getId()); ?>
$j('#product-collection-image-<?php echo $_product->getId(); ?>').hover(function(){
$j(this).attr('src','<?php echo Mage::helper(catalog/image)->init($_product, thumbnail) ?>');
});

open a modal windows in a server

Hi everyone I have a modal windows in joomla 3.0!
I pass the router to javascript like this
<?php $link =JURI::root().'index.php?option=com_projects&view=proyectos&format=raw&task=todosProyecto&id='. $item->id;?>
<li class="item" data-id="id-<?php echo $item->id ?>" data-type="<?php echo $item->categoria ?>">
<a href="#modal" id="<?php echo $link;?>" role="<?php echo $item->id ?>" class="picture" data-toggle="modal">
<img src="<?php echo JURI::root()?><?php echo $item->imagen_portada; ?>"/></a>
<p class="titulo"><?php echo $item->nombre; ?></p>
<p> <?php echo $item->municipio; ?>(<?php echo $item->pais; ?>)<br><?php echo $item->year; ?>
</p>
In local when I open the modal windows it work well, but in the server the modal windows show me the index.php view of this component.
I think that my problem is here, when I take the request for the model I have this.
public function elegirSeleccionados(){
$this->pagination = $this->get('pagination');
$this->items = $this->get('recientes');
$this->list = $this->get('list');
parent::display();
}
But $this->get('list'); is null so I have to asigned a null value to list.
I changed by that..
$this->list = $this->items;
but dont work to!
Any idea!!!
Where is this code?
First part looks like a Layout (views\proyectos\tmpl\default.php) and the second one like a View (views\proyectos\view.html.php).
If it is so, I'd say you are not really loading items in View from the Model. Try using $this->items = $this->get('Items');
But this doesn't explain different results on server and local host.
Hi everyone I solved the problem... the name of my view hava a Camelcase for example itemId and joomla try to find itemid, so donĀ“t find the view and show the default view in the modal.
So I change the name of file without camelCase and now work.!

Magento custom template - edit lightbox sizing

I am using a custom magento template which has a lightbox on the product page. I can set the max width/height for the lightbox in the config as a percentage of the screen (ie 95%). The problem is it then uses this as the default value so even it is is a really small image it will stretch it out to 95% of the screen and cause the image to pixelate.
I would like it to use this percentage as a maximum only but if the actual image is smaller than this then it would use the actual image dimensions.
I have found a file with this code which I think I may need to edit but I am not sure how to go about this in Magento:
<?php
$maxWidth = $zoomHelper->getCfg('lightbox/max_width');
$maxHeight = $zoomHelper->getCfg('lightbox/max_height');
$cfg = '';
if ($maxWidth)
$cfg .= ", maxWidth:'{$maxWidth}'";
if ($maxHeight)
$cfg .= ", maxHeight:'{$maxHeight}'";
?>
Any ideas?
The way I've done this is to load up relatively large images as the base product image. When the product / view is rendering, build a js object that contains urls for large images, and any thumbnails you need. Your lightbox should then use the js object as a data source.
media.phtml
<script> var images = {};</script>
<?php $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
<?php if($_images){?>
<?php $i=0; foreach($_images as $_image){ $i++; ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(108,90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php $this->htmlEscape($_image->getLabel());?>" /><?php } ?>
<script> images.bigsrc = "<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(800,800); ?>" </script>
<?php } ?>
You then have a js object containing urls for whatever size image you would need. Pass that into lightbox / fancybox etc.
You will definitely have to tailor this to match your needs - mostly in terms of creating a js object that you can use.
Some info on resizing images in mage:
http://www.magthemes.com/magento-blog/customize-magentos-image-resize-functionality/

FishPig WordPress - Magento v1.7.0.0 Getting Featured Image to show

We have been trying to get the featured image to show for this block on CMS homepage but so far unsuccessful using FishPig WP Integration extension on Magento v1.7.0.0. However, we are successful in other content from the blog's post to show from specified category.
What we are looking to do is get 2 images to show per post. The rest is good to go. Each section is considered a post. I've linked two screenshots with explanations for visual aid.
The area on the dev site where we are trying to get this done on is:
https://devtest.eboost.com
The relevant block of code for the Press section is
<div id="pressblock">
<?php
//$press_posts = Mage::getResourceModel('wordpress/image')->addIsPublishedFilter()->addCategorySlugFilter('press');
$press_posts = Mage::getResourceModel('wordpress/post_collection')->addIsPublishedFilter()->addCategorySlugFilter('press');
$presstotal = count($press_posts->getAllIds());
$presstotid = $press_posts->getAllIds();
//i<=2 means displays last 2 posts
//display latest 2 posts...
$k = 0;
$nopages = ceil($presstotal/6);
$pag = 1;
for($j=$presstotal - 1; $j>=0; $j--)
{
$k++;
if($k == 1)
{
if($pag == 1)
{
echo '<section id="page-'.$pag.'" class="active">';
$pag++;
}
else
{
echo '<section id="page-'.$pag.'">';
$pag++;
}
}
?>
<div class="<?php if($k%2 == 0) echo 'press_right'; else echo 'press_left';?>">
<div class="pree_emty">
<?php
/*
GPSM 01-23-13:
Some attempts to get the featured image to show. I don't see a variable to display any image really. The only thing that shows image is post_content but that shows the content as well... Maybe we can filter the image from there?
Maybe we can use some of the code from "app/design/frontend/default/eboost/template/wordpress/post/list.phtml" or something.
The following StackOverflow post looks to have promising suggestions:
http://stackoverflow.com/questions/10169968/wordpress-posts-on-magento
Check "app/code/community/Fishpig/Wordpress/Model/Image.php" for functions to display image stuff
*/
//echo $press_posts->getItemById($presstotid[$j])->post_content;
//print_r($press_posts->getItemById($presstotid[$j]));
//echo $press_posts->getItemById($presstotid[$j])->getFeaturedImage();
?>
<img src="<?php echo $press_posts->getItemById($presstotid[$j])->getFeaturedImage(); ?>" width="204" height="204" alt="" />
<?php/*<img src="<?php echo $this->getSkinUrl('images/pree_emty.png');?>" width="204" height="204" alt="" />*/?>
</div>
<div class="press_txt">
<h3><?php echo $press_posts->getItemById($presstotid[$j])->getPostTitle(); ?></h3>
<p><?php echo substr(strip_tags($press_posts->getItemById($presstotid[$j])->getPostContent()), 0, 150); ?></p>
<p><img src="<?php echo $this->getSkinUrl('images/viewfull_btn.png');?>" width="168" height="30" alt="" /></p>
</div>
</div>
<?php
if($k >= 6)
{
echo "</section>";
$k = 0;
}
}
if($k < 6)
{
echo "</section>";
}
?>
</div><!--#pressblock-->
2 screenshots for visual aid:
Best Regards,
George
Figured it out...
Essentially we pulled the custom field image from the posts. We will be making another custom field for the posts for another image. So, one image from post will be for the frontpage->press block and the second image will be displayed in a fancybox overlay.
Here is the relevant code snippet:
http://www.filedropper.com/code_1
^^ posting the code this time around screwed with the formatting and figured to just save it to a file "code.php", upload to free upload site, post here... I followed the posting instructions like last time to post the snippet but I must be doing something wrong but don't have time now to figure that out...
Regards,
George

Slimbox integration with Virtuemart 2, Joomla 2.5

I am trying to replace the default lightbox 'modal' to 'slimbox', because 'modal' doesn't have the navigation arrows.
Demo of slimbox with navigations
Demo of modal without navigations
I am using these paths to modify the calling of slimbox
[templatename]/html/com_virtuemart/productdetails/default.php
components/com_virtuemart/productdetails/default.php
Joomla v2.5
Virtuemart 2.0.6
Slimbox2
The following is my attempt:
//Enable Slimbox2 plugin
$front = JURI::root(true).'/components/com_virtuemart/assets/';
$document = JFactory::getDocument();
$document->addStyleSheet($front.'js/slimbox/slimbox.css');
$document->addScript($front.'js/slimbox/slimbox2.js');
$js = 'jQuery(document).ready(function($) { $("a.lightbox").slimbox(); });';
$document->addScriptDeclaration($js);
//output thumbnail
echo $this->product->images[0]->displayMediaThumb('class="product-image"',true,'class="lightbox" rel="lightbox"'.$this->product->virtuemart_product_id.'"',true,true);
//unset first image not to be show amont additional ones
unset ($this->product->images[0]);
?>
But its still not working I wondered what's wrong?
[Reference][3]
You aren't applying the slimbox class to the image reference, your applying it to the container of the image aren't you? You need to deal with the image file url directly in my opinion.
// get the file_url of the first image
$imgPath = $this->product->images[0]->file_url;
// output the image
<a class="slimbox" href="<?php echo $imgPath; ?>">
<img src="<?php echo $imgPath; ?>" alt="" />
</a>

Resources