I have an attribute on my product view and list pages that displays a preview video on a separate page. I'm pulling in the attribute using my themes product/view.phtml and product/list.phtml. It has an image button that shows preview now. The code is have is below.
<img src="/graphics/preview-now.png" align="absmiddle" style="margin-top: 10px;" alt="Preview Now">
The problem is that I don't want this image to display if the product attribute is null or blank. I tried the code below in a few variations but that wouldn't work.
< ?php if($_product->getvideo_src() != '') { ?>
<span><img src="/graphics/preview-now.png" align="absmiddle" style="margin-top: 10px;" alt="Preview Now"></span>
< ?php } ?>
Try using isset. Also your magic get formatting is off. You had getvideo_src() when it should be camel-cased like getVideoSrc().
<?php if(isset($_product->getVideoSrc())) { ?>
<span><img src="/graphics/preview-now.png" align="absmiddle" style="margin-top: 10px;" alt="Preview Now"></span>
<?php } ?>
Try
<?php if($_product->getVideoSrc()) : ?>
...
<?php endif; ?>
or
<?php if($_product->getData('video_src')) : ?>
...
<?php endif; ?>
Related
I would like to remove the else statement in the following code.
How shall I convert the if statement, so it still works (route is correct/ logo is being shown)?
<div class="logo a">
<a href="<?=$site_url;?>">
<?php if(isset($settings['site_logo_image']) && $settings['site_logo_image'] != '') { ?>
<img src="<?=$site_url;?>_img/logo.png" class="image_logo" border="0" height="40" alt="<?=(isset($settings['site_logo']) ? $settings['site_logo'] : 'Hello');?>" />
<?php } else { ?>
<?=(isset($settings['site_logo']) ? $settings['site_logo'] : 'Hello');?>
<?php } ?>
</a>
</div>
If I leave out the if prefix, it's not working.
I am not a pro in php and actually have to do with frontend stuff...
Thanks
It's a bit tricky to read php interspersed with HTML. Once you get the knack of it, though, it's straightforward. Delete everything from else { to the next }. Like this.
<div class="logo a">
<a href="<?=$site_url;?>">
<?php if(isset($settings['site_logo_image']) && $settings['site_logo_image'] != '') { ?>
<img src="<?=$site_url;?>_img/logo.png" class="image_logo" border="0" height="40" alt="<?=(isset($settings['site_logo']) ? $settings['site_logo'] : 'Hello');?>" />
<?php } ?>
</a>
</div>
Pro tip A language-aware IDE like VSCODE or PhpStorm will alert you immediately if you make a mistake doing this sort of thing.
I am trying to load pictures from database to jquery slider
infact what is stored at database is the name of the picture
i implemented this code, it's working without errors but it showing me nothing at slider all is empty
<div id="slider">
<?php
while ($result = mysqli_fetch_object($banner)):
?>
<img src="images/banner/<? $banner['picture'];?>/" width="950" height="400"alt="" title="<strong><? echo $banner['title'];?></strong><span><? echo $banner['description'];?> </span>" />
<?php
endwhile
?>
</div>
name of the table at database is banner in which i have id(INT), picture(varchar 50) title(varchar(100), description(longblob)
query is working and returning number of selected rows
but nothing is shown
You need to echo the result rather than just use the variable...
<div id="slider">
<?php
while ($result = mysqli_fetch_object($banner)):
?>
<img src="images/banner/<?php echo $banner['picture'];?>" width="950" height="400" alt="" title="<strong><? echo $banner['title'];?></strong><span><?php echo $banner['description'];?></span>" />
<?php
endwhile;
?>
</div>
I have some toruble with displaying terms of service.
At the cart page all works fine: http://mtxt.ibroken.ru/component/virtuemart/cart.html?Itemid=0
(bottom link) opens popup with text, generated by
<?php echo $this->cart->vendor->vendor_terms_of_service; ?>
code.
But i have button on the shop page http://mtxt.ibroken.ru/magazin.html (top button at right side), which must display same text...
At present moment text written in /modules/mod_virtuemart_cart/tmpl/default.php file. But how to get it in this file from shop interface by using PHP?
pps. Ugly English, sorry for that :)
You need to modify /modules/mod_virtuemart_cart/tmpl/default.php (or your override) and add this code just after line 3:
vmJsApi::js ('facebox');
vmJsApi::css ('facebox');
$document = JFactory::getDocument ();
$document->addScriptDeclaration ("
jQuery(document).ready(function($) {
$('div#full-tos').hide();
$('a#terms-of-service').click(function(event) {
event.preventDefault();
$.facebox( { div: '#full-tos' }, 'my-groovy-style');
});
});
");
And add this code just after line 53
<div class="show_cart">
<?php
if(!class_exists('VirtueMartModelVendor'))
require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'vendor.php');
$vendor = VmModel::getModel('vendor');
$vendor = $vendor->getVendor();
?>
<br />
<span style="z-index: 0;">
<a href="<?php JRoute::_ ('index.php?option=com_virtuemart&view=vendor&layout=tos&virtuemart_vendor_id=1') ?>" class="terms-of-service" id="terms-of-service" rel="facebox" target="_blank">
<?php echo JText::_ ('COM_VIRTUEMART_CART_TOS_READ_AND_ACCEPTED'); ?>
</a>
</span>
<div id="full-tos">
<h2><?php echo JText::_ ('COM_VIRTUEMART_CART_TOS'); ?></h2>
<?php echo $vendor->vendor_terms_of_service; ?>
</div>
</div>
That shoud do the trick!
I'm attempting to modify an app for facebook that uses php and javascript.
It allows a user to send gifts to each other's wall. When a gift is received, it show's on the app's notification page for that user.
The problem: after a gift is accepted, it still shows on the notifications page. I suppose because it was deemed necessary in order for the point system as well as the history functions to operate properly. It appears that gifts older than 30 days are no longer displayed. I tried to permanently change the date of the gift after it's accepted.
Can anyone please suggest possible ways to:
Option 1. After the gift is accepted, permanently change it to a different image to inform the user "you have already accepted this". Without removing it from the database.
Option 2. Remove the gift from the page (or prevent it from being displayed) after it's accepted...without deleting it from the database. .hide and display:none; are not viable options because the gift will be displayed again...every time the page loads.
Option 3. Last and least desired option, remove the gift from the page and database as well.
The original code for that page is below. The part of the code that I'm guessing needs to be modified is located between the asterisk dividers. I hope it's not too difficult to follow :-/
Thanks for your time.
<?php
if(!isset($facebook))
{
$user_id=$_POST['user_id'];
}
else
{
$user_id=$user_info['UserID'];
}
$news_limit=$current_time-2592000;
$history_query=mysql_query("SELECT * FROM ".$exchange_table." WHERE Time>'$news_limit'
AND ReceiverID='$user_id' ORDER BY Time DESC");
$history_num=mysql_num_rows($history_query); ?>
<div style="font-size:14px;width:720px;padding:10px;<?php echo $background_one; ?>"
align="left">
<div style="font-weight:bold;font-size:16px;color:#6f6f6f;">
<?php echo $nav_info['home']; ?>
</div>
<div style="width:100%;margin-top:10px;" align="center">
<img src="<?php echo $app_info['image_url']; ?>divider.gif">
<img src="<?php echo $app_info['image_url']; ?>divider.gif">
<img src="<?php echo $app_info['image_url']; ?>divider.gif">
</div> <?php
if($history_num>0)
{
$gift_query=mysql_query("SELECT GiftID,Name,Image FROM ".$gift_table." WHERE
Type='1'");
while($gift_info=mysql_fetch_assoc($gift_query))
{
$gift_array[$gift_info['GiftID']]['name']=$gift_info['Name'];
$gift_array[$gift_info['GiftID']]['image']=$gift_info['Image'];
} ?>
<div style=""> <?php
$i=1;
while($history_info=mysql_fetch_assoc($history_query))
{ ?>
<div style="margin-top:10px;">
<div style="float:left;width:75px;">
<img src="<?php echo
$app_info['upload_url'].$gift_array[$history_info['GiftID']]['image']; ?>"
style="width:75px;height:75px;">
</div>
<div style="float:left;margin-left:10px;">
<span style="font-size:18px;"><span id="month<?php echo $i; ?>"></span> -
Gift Received!</span><br>
You received a(n) <b><?php echo $gift_array[$history_info['GiftID']]
['name']; ?></b> from <b><fb:name uid='<?php echo $history_info['FacebookID']; ?>'
linked='false'></fb:name></b>!<br>
**************************************************************
<input id="share_button<?php echo $i; ?>" onclick="shareFeed('<?php echo
$gift_array[$history_info['GiftID']]['image']; ?>','<?php echo $history_info['GiftID'];
?>','<?php echo $gift_array[$history_info['GiftID']]['name']; ?>')" type="image" src="
<?php echo $app_info['image_url']; ?>share_button.png"
onmouseover="convert('share_button<?php echo $i; ?>','share_hover.png')"
onmouseout="convert('share_button<?php echo $i; ?>','share_button.png')"
style="height:29px;margin-top:5px;">
</div>
**************************************************************
<br style="clear:both;">
</div>
<script>
var date_text="";
var time_date=new Date();
var monthNames=
["January","February","March","April","May",
"June","July","August","September","October","November","December"];
time_date.setTime(<?php echo $history_info['Time']*1000; ?>);
document.getElementById('month<?php echo $i; ?
>').innerHTML=monthNames[time_date.getMonth()]+" "+time_date.getDate();
</script> <?php
$i++;
} ?>
</div> <?php
}
else
{ ?>
<div style="font-size:14px;font-weight:bold;margin-top:20px;" align="center">
No giftss received over the past 30 days.
</div> <?php
} ?>
</div>
i have this code:
<body>
<div class="header">
<?php if (isset($_SESSION['user_id']) && !isset($menu)) { ?>
<div class="menu_holder">
<ul>
<li>
<a href="<?php echo ADDRESS; ?>menu.php" class="green_link">
<img src="<?php echo IMAGES; ?>template/menu.gif" width="51" height="20" border="0" />
</a>
</li>
</ul>
</div>
<?php } ?>
<?php
if (!isset($plainHeader))
{
$plainHeader = " ";
?>
<img src="<?php echo IMAGES; ?>template/logo.gif" width="160" height="94" />
<?php
}
?>
</div>
<br/>
<?php $id_to = $user['profile_id_contact']; ?>
<div class="main_content">
<center>
<div class="innerContainer">
<span class="headings2">FREE CHAT CONTACTS</span>
<form id="message_area" style="display:none" method="post" action="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to ?>">
<?php
if (count($users) > 0)
{
foreach ($users as $user)
{
//some php here
?>
<a href="#" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this); return false;" >
<?php echo $uniqueCode1?><span class="pink_text"><?php echo $uniqueCode2?></span><?php echo $uniqueCode3?>
</a>
<textarea name="message" rows="10" cols="20"></textarea>
<input name="Submit" type="submit" value="Send"></input>
<?php
}
}
?>
</form>
</div>
</center>
</div>
</body>
as my code is now the form tag is in the wrong place because my tag links does not show.
where must i put my form tag so that when i click on any of the uniquecode links i pass the correct $id_to in the action??? when i move the form tag after the my links show but regardless of which link i click on it passes the first link's $id_to with the action. i have also tried to pass $id_to as a hidden field which i had after the sumbit but still it passes the first link's id
please help? i have been struggeling with this for some time now...i cannot redirect the page via JS becuase this site is for a MOBILE aka mobi site
please help? im desperate
thank you
if i move the form tag and have it like this:
messageSent.php?id=">
and i view the page source $id_to contains correct id but as sson as i go to sentMessage.php the id in the url is incorrect
To pass a id to the next page in a link you need to add "?id='.$id.'" at the end of the url.
e.g.
<a href="<?php echo ADDRESS; ?>menu.php?id=5" class="charcoal_link" style="line-height: 20px;">
To make sure that each link is different you can right click and copy the url to double check.