images not viewing
9 posts by 3 authors in: Forums > CMS Builder
Last Post: June 20, 2013 (RSS)
Hi all,
here is my block of code for displaying images on my homepage:
<?php if ($upload = @$homepageRecord['images'][0]):?>
<img src="<?php echo $upload['urlPath'] ?>" width="71" height="54" alt="" />
<?php endif?>
is there any reason why this is not working? :)
Many Thanks,
eldon
By gregThomas - June 17, 2013
Hi Eldon,
In what way is it not working? Is the image tag not being created at all, or is it not loading the image inside of the image tag?
Would it be possible to attach or post the entire code for the page?
Thanks!
Greg
PHP Programmer - interactivetools.com
Hi Greg,
They don't appear to be loading at all...code below:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/enlig124/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load record from 'home_page'
list($home_pageRecords, $home_pageMetaData) = getRecords(array(
'tableName' => 'home_page',
'where' => '', // load first record
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$home_pageRecord = @$home_pageRecords[0]; // get first record
if (!$home_pageRecord) { dieWith404("Record not found!"); } // show error message if no record found
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tara Preston - Welcome to Enlighten The Soul</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
body { font-family: arial; }
.instructions { border: 3px solid #000; background-color: #EEE; padding: 10px; text-align: left; margin: 25px}
</style>
</head>
<body>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="keywords" content="Akashic Record Readings, Akashic records, Akasha, soul healing, holistic healing, Intuitive Healing, energy healing, energy therapy, healing touch practitioner, authentic, soul-level, soul discovery, purpose, life purpose, soul purpose, heal, clear energetic blocks, soul realignment, intuitive, coaching, guidance, spiritual healing, remove blocks, clear patterns, life purpose, intuitive reading, co-create, manifest, clear blocks, soul groups, inspired creative living, self-love, feminine flow, heart centered living, energetic alignment, success, passion, spirit guides, professional intuitive, healer, past life healing, tara preston, tara favreau, soul gifts, gifts, relationship healing, divine guidance, intuitive support, chakra healing, soul realignment pracitioner" />
<meta name="description" content="Akashic Record Readings from Enlighten the Soul" />
<meta name="author" content="Tara Preston www.enlightenthesoul.com" />
<meta name="copyright" content="www.enlightenthesoul.com, Tara Preston" />
<meta name="distribution" content="Global" />
<meta name="revisit-after" content="30 days" />
<meta name="robots" content="home, follow" />
<meta name="url" content="http://www.enlightenthesoul.com/" />
<meta name="language" content="English" />
<meta name="viewport" content="width=device-width">
<link rel="canonical" href="">
<link rel="icon" type="image/ico" href="favicon.ico">
<link href="style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="colorbox.css" />
<script src="js/jquery.min.js"></script>
<script src="js/jquery.colorbox.js"></script>
<script>
$(document).ready(function(){
//Examples of how to assign the Colorbox event to elements
$(".vimeo").colorbox({iframe:true, innerWidth:500, innerHeight:409});
$(".iframe").colorbox({iframe:true, width:580, height:870});
$(".iframe1").colorbox({iframe:true, width:624, height:360});
$(".iframe2").colorbox({iframe:true, width:580, height:1060});
$(".callbacks").colorbox({
onOpen:function(){ alert('onOpen: colorbox is about to open'); },
onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
});
$('.non-retina').colorbox({rel:'group5', transition:'none'})
$('.retina').colorbox({rel:'group5', transition:'none', retinaImage:true, retinaUrl:true});
//Example of preserving a JavaScript event for inline calls.
$("#click").click(function(){
$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
return false;
});
});
</script>
<body>
<div id="main_contain">
<div id="inner_contain">
<div id="header">
<div id="logo"><img src="images/logo.png" width="518" height="367" usemap="#Map">
<map name="Map">
<area shape="rect" coords="100,8,466,156" href="index.php">
</map>
</div>
<div id="right_header">
<div id="right_text"><?php echo htmlencode($home_pageRecord['right_header_text']) ?></div>
</div>
<div id="navigation">
<div id="main_menu">
<ul id="coolMenu">
<li><a href="index.php" class="current_page" style="color:#000;">Home</a></li>
<li><a class='iframe' href="about.php">About</a></li>
<li><a href="blog.php">Blog</a></li>
<li><a href="service.php">Services</a>
<!-- <ul class="noJS">
<li><a href="full_story.html">Full Story</a></li>
<li><a class="various3" href="faq.html">FAQ</a></li>
</ul>-->
</li>
<li><a class='iframe2' href="testimonial.php">Testimonials</a></li>
<li><a href="contact.php">Connect</a></li>
</ul>
</div>
</div>
</div>
<div id="lower_main">
<div id="left_side">
<div id="left_heading1"><?php echo htmlencode($home_pageRecord['top_text']) ?></div>
<div id="welcome_contain">
<div class="page_heading"><?php echo htmlencode($home_pageRecord['title']) ?></div>
<div class="page_textcontain">
<p><?php echo $home_pageRecord['opening_paragraph']; ?></p>
<p class="test_text1"><em><?php echo htmlencode($home_pageRecord['middle_quotations']) ?></em></p>
<p><?php echo $home_pageRecord['remaining_paragraphs']; ?></p>
</div>
</div>
<div id="lower_boxcontain"><?php if ($upload = @$homepageRecord['images'][0]):?>
<img src="<?php echo $upload['urlPath'] ?>" width="71" height="54" alt="" />
<?php endif?>
<?php if ($upload = @$homepageRecord['images'][0]):?>
<img src="<?php echo $upload['urlPath'] ?>" width="71" height="54" alt="" />
<?php endif?>
<?php if ($upload = @$homepageRecord['images'][0]):?>
<img src="<?php echo $upload['urlPath'] ?>" width="71" height="54" alt="" />
<?php endif?>
<?php if ($upload = @$homepageRecord['images'][0]):?>
<img src="<?php echo $upload['urlPath'] ?>" width="71" height="54" alt="" />
<?php endif?></a></div>
</div>
<div id="right_sidebar">
<div class="widget_contain"><a class='iframe1' href="youtube.html" title="youtube"><img src="images/youtube.jpg" width="235" height="151"></a></div>
<div class="widget_contain1">
<div class="widget_text"><?php echo htmlencode($home_pageRecord['subscribe']) ?></div>
<div class="widget_form">
<?php
if(!isset($_GET['action'])) :
?>
<form action="http://enlightenthesoul.us6.list-manage.com/subscribe/post?u=3cbb55f97c8a76ef6bab792b3&id=2237a131b6" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" novalidate>
<input type="email" name="EMAIL" class="inbox" id="mce-EMAIL" value="your@email.here" onblur="if(this.value=='') this.value='your@email.here';" onfocus="if(this.value=='your@email.here') this.value='';" type="text">
<div id="form_arrow"><img src="images/form_arrow.png" width="46" height="37"></div>
<div class="widget_submit">
<input type="image" name="imageField" name="subscribe" id="mc-embedded-subscribe" src="images/submit.png">
</div>
</form>
<?php
endif;
if(isset($_GET['action'])) :
?>
<p align='center'>Thank you for subscribing! Please check your email to confirm.<p>
<?php
endif;
?>
</div>
</div>
<div class="widget_contain"><iframe src="//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FEnlighten-The-Soul%2F326234864064583%3Ffref%3Dts&width=235&height=290&show_faces=true&colorscheme=light&stream=false&border_color=%23ccc&header=true" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:235px; height:290px;" allowTransparency="true"></iframe></div>
</div>
</div>
<div id="lower_socialcontain"><a href="#"><img src="images/rss.png" width="30" height="30"></a><a href="https://twitter.com/ElightentheSoul" target="_blank"><img src="images/twitter.png" width="30" height="30"></a><a href="http://www.youtube.com/channel/UCd8MdEUYkeUHjHPtl4juyOA" target="_blank"><img src="images/you_tube.png" width="30" height="30"></a><a href="https://www.facebook.com/pages/Enlighten-The-Soul/326234864064583" target="_blank"><img src="images/facebook.png" width="30" height="30"></a></div>
</div>
<div id="fot_contain">
<div id="fot_innercontain">
<div id="fot_innermain">
<div id="left_fotcontain">
<div id="pack_img"><img src="images/pack_img.png" width="134" height="133"></div>
<div id="fot_formcontain">
<div id="fot_formhead"><?php echo htmlencode($home_pageRecord['ebook_line_1']) ?></div>
<div id="fot_formhead1"><?php echo htmlencode($home_pageRecord['ebook_line_2']) ?></div>
<div id="fot_fcontain">
<form name="form2" method="post" action="">
<input name="textfield" class="inbox1" id="textfield" value="Name" onblur="if(this.value=='') this.value='Name';" onfocus="if(this.value=='Name') this.value='';" type="text">
<input name="textfield" class="inbox1" id="textfield" value="Email" onblur="if(this.value=='') this.value='Email';" onfocus="if(this.value=='Email') this.value='';" type="text">
<div class="widget_submit1">
<input type="image" name="imageField" id="imageField" src="images/submit.png">
</div>
</form>
</div>
</div>
</div>
<div id="right_fotcontain">
<div id="fot_logo"><img src="images/fot_logo.png" width="163" height="63" usemap="#Map2">
<map name="Map2">
<area shape="rect" coords="9,7,154,58" href="index.php">
</map>
</div>
<div id="copyright">Copyright © 2013 Enlighten <br>The Soul
All Rights Reserved.</div>
</div>
</div>
</div>
<div id="fot_cor"><img src="images/site_design.png" width="86" height="42" usemap="#Map3">
<map name="Map3">
<area shape="rect" coords="4,5,82,38" href="#">
</map>
</div>
</div>
</div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-40427183-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>
Thankyou,
eldon
By Jason - June 18, 2013
Hi Eldon,
I took a look at your code and found a couple of things. The first was a simple typo in the code. Your home page record set was in a variable called $home_pageRecord, but the code you were using $homepageRecord when trying to output images.
The other problem is that the code $home_pageRecord['images'][0] pulls the first image element out of the array, but it doesn't remove that element. So if you repeat this line multiple times, it will just output the same image. The best solution here would be to use a foreach loop like this:
<div id="lower_boxcontain">
<?php foreach ($home_pageRecord['images'] as $upload): ?>
<img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
<?php endforeach ?>
</div>
This will go through each element in the array, one at a time. You don't have to worry about checking for a value first, because if there are no elements in the array at all, then the loop will never execute.
Hope this helps!
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Hi Jason,
I used the code you sent as follows:
<div id="lower_boxcontain"> <?php foreach ($home_pageRecord['images'] as $upload): ?>
<img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
<?php endforeach ?>
<?php foreach ($home_pageRecord['images'] as $upload): ?>
<img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
<?php endforeach ?>
<?php foreach ($home_pageRecord['images'] as $upload): ?>
<img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
<?php endforeach ?>
<?php foreach ($home_pageRecord['images'] as $upload): ?>
<img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
<?php endforeach ?></a></div>
</div>
Now I'm getting the following error when I load the page:
Notice: Undefined index: images in /home/enlig124/public_html/index.php on line 130 Warning: Invalid argument supplied for foreach() in /home/enlig124/public_html/index.php on line 130 Notice: Undefined index: images in /home/enlig124/public_html/index.php on line 133 Warning: Invalid argument supplied for foreach() in /home/enlig124/public_html/index.php on line 133 Notice: Undefined index: images in /home/enlig124/public_html/index.php on line 136 Warning: Invalid argument supplied for foreach() in /home/enlig124/public_html/index.php on line 136 Notice: Undefined index: images in /home/enlig124/public_html/index.php on line 139 Warning: Invalid argument supplied for foreach() in /home/enlig124/public_html/index.php on line 139
index available at: http://enlightenthesoul.com/index.php
Help!
Thanks,
ko19
By Jason - June 19, 2013
Hi,
The error here means that there is no field called "images" in home_page section of the CMS. I would first check that section and make sure that the name is right. That should take care of the issue. Also, you won't need to repeat the foreach loop 3 times. The loop means that it will output all of the uploads in that field. If you duplicate the code 3 times, then you will get all the images repeated.
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Hi Jason,
So like this? images is the name of the folder they are found in.
<div id="lower_boxcontain"> <?php foreach ($home_pageRecord['images'] as $upload): ?>
<img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
<?php foreach ($home_pageRecord['images'] as $upload): ?>
<img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
<?php foreach ($home_pageRecord['images'] as $upload): ?>
<img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
<?php foreach ($home_pageRecord['images'] as $upload): ?>
<img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
<?php endforeach ?></a></div>
I have an image that is loading correctly on about page. code looks like this.
<p><?php foreach ($aboutRecord['images'] as $index => $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="390" height="243" alt="" />
<?php endforeach ?></p>
sory not a php guy, just muckin through this.
ko19
By Jason - June 20, 2013
Hi,
I took a look at the page again and it looks like you are outputting 4 images, however, they don't look like they are coming from the CMS. Is that right?
The foreach loop method that I showed you is only used when you are trying to output images that have been uploaded directly to a record in the CMS through an upload field. Do you have a separate upload field in your home page section? If so, you can use this code to output all the images uploaded to that section:
<div id="lower_boxcontain">
<?php foreach ($home_pageRecord['images'] as $upload): ?>
<img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
<?php endforeach
</div>
This code assumes that your upload field in your homepage section is called "images". So in this case, if you uploaded 4 images to that upload field, all 4 would be output using this 1 foreach loop.
Hope this helps.
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/