Remove this section of code and put it into another loop - php

I've been racking my brain for weeks trying to remove this block of code, it's from paid memberships pro plugin.
I need to remove the below section as it produces the file fields on the user profile.
need to remove it and put it in a loop of its own and then print it, as I need it to be in a separate <section> from the rest of the fields that are in that original loop.
//----Trying to remove this piece of code----//
?>
<strong><?php echo $field[0]; ?></strong>
<div class="Test"><?php echo pmpromd_display_file_field($meta_field); ?></div>
<?php
//---This is the FullSnippet with the above code included----//
if(!empty($fields_array))
{
foreach($fields_array as $field)
{
if(empty($field[0]))
break;
// Fix for a trailing space in the 'fields' shortcode attribute.
if ( $field[0] === ' ' ) {
break;
}
$field_val = $field[1];
$meta_field = $pu->$field_val;
if(!empty($meta_field))
{
?>
<section class="pmpro_member_directory_<?php echo esc_attr($field[1]); ?>">
<?php
if(is_array($meta_field) && !empty($meta_field['filename']) )
{
//this is a file field
?>
<strong><?php echo $field[0]; ?></strong>
<div class="brendan"><?php echo pmpromd_display_file_field($meta_field); ?></div>
<?php
}elseif(is_array($meta_field)){
//this is a general array, check for Register Helper options first
if(!empty($rh_fields[$field[1]])) {
foreach($meta_field as $key => $value)
$meta_field[$key] = $rh_fields[$field[1]][$value];
}
?>
<strong><?php echo $field[0]; ?></strong>
<ul class="servicesList"><?php echo '<li>'.implode("</li>\n<li>",$meta_field).'</li>';?></ul>
<?php
}
elseif(!empty($rh_fields[$field[1]]) && is_array($rh_fields[$field[1]]) )
{
?>
<strong><?php echo $field[0]; ?></strong>
<?php echo $rh_fields[$field[1]][$meta_field]; ?>
<?php
}
else
{
if($field[1] == 'user_url')
{
?>
<?php echo $field[0]; ?>
<?php
}
else
{
?>
<strong><?php echo $field[0]; ?></strong>
<?php
$meta_field_embed = wp_oembed_get($meta_field);
if(!empty($meta_field_embed)){
echo $meta_field_embed;
}else{
echo make_clickable($meta_field);
}
?>
<?php
}
}
?>
</section>
<?php
}
}
}
?>

Related

Syntax error, Unexpected else T_ELSE [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I got this error from my product.tpl, inserted some codes to manipulate my price and stocks, im looking to end my code using this } absolutely but i got no luck.
<?php if($price == "₱0.00" && $stock == "In Stock" ) { ?><?php echo "Customizable"; ?>
<?php } else { ?>
<?php if($price == "₱0.00" && $stock == "For inquiry") { ?><?php echo "For inquiry"; ?>
<?php } else { ?>
<?php if($price) { ?><?php echo $price; ?></h4>
<?php } ?>
Originally the code is this and i added to a little bit of code to the highlighted code
<ul class="list-unstyled">
<?php if (!$special) { ?>
<li>
<h4><?php if($price) { ?><?php echo $price; ?></h4>
</li>
<?php } else { ?>
<li><span style="text-decoration: line-through;"><?php echo $price; ?>
</span>
<h4><?php echo $special; ?></h4></li>
<?php } ?>
<?php if ($tax) { ?>
<li><?php echo $text_tax; ?><?php echo $tax; ?></li>
<?php } ?>
<?php if ($points) { ?>
<li><?php echo $text_points; ?> <?php echo $points; ?></li>
<?php } ?>
<?php if ($discounts) { ?>
<?php foreach ($discounts as $discount) { ?>
<li><?php echo $discount['quantity']; ?><?php echo $text_discount; ?>
<?php echo $discount['price']; ?></li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
Formatting your code properly really helps. Does the code below work the way you want it to?
<?php if(!$special) { ?>
<ul class="list-unstyled">
<li>
<?php if($price == "₱0.00" && $stock == "In Stock" ) {
echo "Customizable";
} else if($price == "₱0.00" && $stock == "For inquiry") {
echo "For inquiry";
} else if($price) { ?>
<h4><?=$price;?></h4>
<?php } else { ?>
<span style="text-decoration: line-through;"><?=$price;?></span>
<h4><?=$special;?></h4>
<?php } ?>
</li>
<?php if($tax) { ?>
<li><?=$text_tax.' '.$tax;?></li>
<?php } ?>
<?php if($points) { ?>
<li><?=$text_points.' '.$points;?></li>
<?php } ?>
<?php if(count($discounts)) { foreach ($discounts as $discount) { ?>
<li><?=$discount['quantity'].' '.$text_discount.' '.$discount['price'];?></li>
<?php } } ?>
</ul>
<?php } ?>
Use proper format, too many tags of php, use codes look like this.
<?php
if($price == "₱0.00" && $stock == "In Stock" ) {
echo "Customizable";
} else if($price == "₱0.00" && $stock == "For inquiry") {
echo "For inquiry";
} else if($price) {
echo $price;
}
?>
The if elseif is used like below:
<?php if($condition) { //action } elseif($condition2) { //action2 } ?>
I think you want this:
<ul class="list-unstyled">
<?php if(!$special) { ?>
<li>
<h4><?php echo $price; ?></h4>
</li>
<?php }else{ ?>
<li>
<span style="text-decoration: line-through;"><?php echo $price; ?></span>
<h4><?php echo $special; ?></h4>
</li>
<?php if($tax) { echo '<li>'.$text_tax.$tax.'</li>';} ?>
<?php if($points) { echo '<li>'.$text_points.$points.'</li>';} ?>
<?php
if($discounts){
foreach ($discounts as $discount) {
echo '<li>'.$discount["quantity"].$text_discount'<br>'.$discount['price'].'</li>';
}
}
?>
<?php } ?>
</ul>

How to modify Jomi Joomla Template

I have a Jomi installation and I see that social icons are inserted at the bottom of my article while I would display them after the head section. What should I look for to modify this since the template settings just allow me to turn on/off the social bar? Should I look inside layouts or styles folder?
On feeling I looked into layouts/com_content/article and there is a default.php that looks something like a template for my articles, but I cannot find anything about social bar, here is its content:
<?php
/**
* #package Warp Theme Framework
* #author YOOtheme http://www.yootheme.com
* #copyright Copyright (C) YOOtheme GmbH
* #license http://www.gnu.org/licenses/gpl.html GNU/GPL
*/
// no direct access
defined('_JEXEC') or die;
// get view
$menu = JSite::getMenu()->getActive();
$view = is_object($menu) && isset($menu->query['view']) ? $menu->query['view'] : null;
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers');
// Create shortcuts to some parameters.
$params = $this->item->params;
$images = json_decode($this->item->images);
$urls = json_decode($this->item->urls);
$canEdit = $this->item->params->get('access-edit');
$user = JFactory::getUser();
?>
<div id="system">
<?php if ($this->params->get('show_page_heading', 1)) : ?>
<h1 class="title"><?php echo $this->escape($this->params->get('page_heading')); ?></h1>
<?php endif; ?>
<article class="item"<?php if ($view != 'article') printf(' data-permalink="%s"', JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catslug), true, -1)); ?>>
<?php if ($params->get('show_title')) : ?>
<header>
<?php if (!$this->print) : ?>
<?php if ($params->get('show_email_icon')) : ?>
<div class="icon email"><?php echo JHtml::_('icon.email', $this->item, $params); ?></div>
<?php endif; ?>
<?php if ($params->get('show_print_icon')) : ?>
<div class="icon print"><?php echo JHtml::_('icon.print_popup', $this->item, $params); ?></div>
<?php endif; ?>
<?php else : ?>
<div class="icon printscreen"><?php echo JHtml::_('icon.print_screen', $this->item, $params); ?></div>
<?php endif; ?>
<?php if ($params->get('show_create_date')) : ?>
<header class="clearfix">
<time datetime="<?php echo substr($this->item->created, 0,10); ?>" pubdate>
<span class="day"><?php echo JHTML::_('date',$this->item->created, JText::_('d')); ?></span>
<span class="month"><?php echo JHTML::_('date',$this->item->created, JText::_('M')); ?></span>
<span class="year"><?php echo JHTML::_('date',$this->item->created, JText::_('Y')); ?></span>
</time>
<?php endif; ?>
<h1 class="title"><?php echo $this->escape($this->item->title); ?></h1>
<?php if (($params->get('show_author') && !empty($this->item->author)) || $params->get('show_category')) : ?>
<p class="meta">
<?php
if ($params->get('show_author') && !empty($this->item->author )) {
$author = $this->item->created_by_alias ? $this->item->created_by_alias : $this->item->author;
if (!empty($this->item->contactid) && $params->get('link_author') == true) {
$needle = 'index.php?option=com_contact&view=contact&id=' . $this->item->contactid;
$menu = JFactory::getApplication()->getMenu();
$item = $menu->getItems('link', $needle, true);
$cntlink = !empty($item) ? $needle . '&Itemid=' . $item->id : $needle;
echo JText::sprintf('<i class="icon-user"></i>');
echo JText::sprintf('COM_CONTENT_WRITTEN_BY', JHtml::_('link', JRoute::_($cntlink), $author));
} else {
echo JText::sprintf('<i class="icon-user"></i>');
echo JText::sprintf('COM_CONTENT_WRITTEN_BY', $author);
}
}
if ($params->get('show_author') && !empty($this->item->author )) {
echo '. ';
}
if ($params->get('show_category')) {
echo JText::_('<i class="icon-folder-open-alt"></i>').' ';
echo JText::_('TPL_WARP_POSTED_IN').' ';
$title = $this->escape($this->item->category_title);
$url = ''.$title.'';
if ($params->get('link_category') AND $this->item->catslug) {
echo $url;
} else {
echo $title;
}
}
?>
</p>
<?php endif; ?>
</header>
<?php endif; ?>
<?php
if (!$params->get('show_intro')) {
echo $this->item->event->afterDisplayTitle;
}
echo $this->item->event->beforeDisplayContent;
if (isset ($this->item->toc)) {
echo $this->item->toc;
}
?>
<div class="content clearfix">
<?php
if ($params->get('access-view')) {
if (isset($urls) AND ((!empty($urls->urls_position) AND ($urls->urls_position=='0')) OR ($params->get('urls_position')=='0' AND empty($urls->urls_position) ))
OR (empty($urls->urls_position) AND (!$params->get('urls_position')))) {
echo $this->loadTemplate('links');
}
if (isset($images->image_fulltext) and !empty($images->image_fulltext)) {
$imgfloat = (empty($images->float_fulltext)) ? $params->get('float_fulltext') : $images->float_fulltext;
$class = (htmlspecialchars($imgfloat) != 'none') ? ' class="size-auto align-'.htmlspecialchars($imgfloat).'"' : ' class="size-auto"';
$title = ($images->image_fulltext_caption) ? ' title="'.htmlspecialchars($images->image_fulltext_caption).'"' : '';
echo '<img'.$class.$title.' src="'.htmlspecialchars($images->image_fulltext).'" alt="'.htmlspecialchars($images->image_fulltext_alt).'" />';
}
echo $this->item->text;
if (isset($urls) AND ((!empty($urls->urls_position) AND ($urls->urls_position=='1')) OR ( $params->get('urls_position')=='1') )) {
echo $this->loadTemplate('links');
}
// optional teaser intro text for guests
} elseif ($params->get('show_noauth') == true AND $user->get('guest')) {
echo $this->item->introtext;
// optional link to let them register to see the whole article.
if ($params->get('show_readmore') && $this->item->fulltext != null) {
$link1 = JRoute::_('index.php?option=com_users&view=login');
$link = new JURI($link1);
echo '<p class="links">';
echo '<a href="'.$link.'">';
$attribs = json_decode($this->item->attribs);
if ($attribs->alternative_readmore == null) {
echo JText::_('COM_CONTENT_REGISTER_TO_READ_MORE');
} elseif ($readmore = $this->item->alternative_readmore) {
echo $readmore;
if ($params->get('show_readmore_title', 0) != 0) {
echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
}
} elseif ($params->get('show_readmore_title', 0) == 0) {
echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE');
} else {
echo JText::_('COM_CONTENT_READ_MORE');
echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
}
echo '</a></p>';
}
}
?>
</div>
<?php if ($canEdit) : ?>
<p class="edit"><?php echo JHtml::_('icon.edit', $this->item, $params); ?> <?php echo JText::_('TPL_WARP_EDIT_ARTICLE'); ?></p>
<?php endif; ?>
<?php echo $this->item->event->afterDisplayContent; ?>
</article>
</div>
The only point that could reasonable be the social bar is this line:
<?php echo $this->item->event->afterDisplayContent; ?>
However it looks like a ore wider concept, since afterDisplayContent probably handles many things, and here is where I stop, I have no idea where to look for afterDisplayContent event definition, I guess that I should find an entry for social bar and copy/paste in the position that I want in my module.

Endforeach loop different class for first item

I'm not that good at php. What i have is a list of items looped with endforeach. What I want is that the first loop will have a class of col-lg-12 and from the second one that class will become col-lg-6. How can I achive that?
Here's the code:
<?php $firstLoop = true;
foreach( $network_value as $key => $value ){
if( $firstLoop ){
echo '<div class="col-lg-12">';
}
echo '<div class="col-lg-6">';
$firstLoop = false;
} ?>
^This is the code that I've tried, but it's not working how i wanted.
<?php if ($img): ?>
<img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
<?php endif; ?>
<h4>
<div class="circle"><?php echo $datePublic = date('d M', strtotime($page->getCollectionDatePublic())); ?></div>
<br>
<a class="blogTitle" href="<?php echo $url ?>" target="<?php echo $target ?>"><?php echo $title ?></a></h4>
<h6>Posted by <?php echo $author; ?></h6>
<br>
<p><?php echo $description ?></p>
</div>
<?php endforeach; ?>
The most simple way to do it is to add a counter and check if it is the first value in the counter.
<?php
$counter = 0;
foreach( $network_value as $key => $value )
{
if($counter == 0){
echo '<div class="col-lg-12">';
} else {
echo '<div class="col-lg-6">';
}
$counter++;
}
?>
Also I want to add that there are two ways of using foreach and if-statements, but you are trying to mix them, which is wrong.
The first method is using brackets "{" and "}":
foreach($users as $user) {
// do things for each user
echo $user->name; // Example of writing out users name
}
And if-statement:
if(true) {
// do something
}
The second method is using "foreach(statement):" and "endforeach;"
foreach($users as $user):
// do things for each user
echo $user->name; // Example of writing out users name
endforeach;
And if-statement:
if(true):
// do something
endif;
Edited:
In your case you can use:
<?php
foreach ($pages as $key=>$page):
if($key==0){
echo '<div class="col-lg-12">';
} if($key==1){
echo '<div class="col-lg-6">';
}
endforeach; ?>
Or you can use:
<?php
foreach ($pages as $key=>$page):
if($key==0){
echo '<div class="col-lg-12">';
} else {
echo '<div class="col-lg-6">';
}
endforeach; ?>
OLD:
foreach($array as $key=>$row){
if($key==0){
echo '<div class="col-lg-12"></div>';
}
if($key==5){
echo '<div class="col-lg-6"></div>';
}
// OR try use %
if($key%2 == 0){
echo '<div class="col-lg-12"></div>';
} else {
echo '<div class="col-lg-12"></div>';
}

Magento Grouped Product Not showing products / prices

When building a new grouped product using already created and in stock simple products the finished grouped product not show the table listing the product titles and prices on the right side column when using my custom template.
When the custom template is turned off and the default Magento template is in use the template displays the titles and prices correctly.
There is an issue with the grouped product template code that is preventing this portion of information from being displayed but the code of /app/design/frontend/mytemplate/default/template/catalog/product/view/type/grouped.phtml is the same as the default template of Magento.
Any one know how to resolve this?
It's hard to tell, but perhaps the template file isn't used. You could check if the layout file in your template has a block that refers to grouped.phtml in the PRODUCT_TYPE_grouped node. Also check if the view.phtml makes a call like
<?php echo $this->getChildHtml('product_type_data') ?>
to refer to the block.
Compare your template files to:
app\design\frontend\base\default\template\catalog\product\view.phtml
app\design\frontend\base\default\layout\catalog.xml
to see what I mean.
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php echo $this->getBlockHtml('formkey'); ?>
<div class="no-display">
<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
<input type="hidden" name="related_product" id="related-products-field" value="" />
</div>
<?php
//Product collaterals
$section = array();
//Related products. $section['related'] is set only if related products (or replacement) exist
$replaceRelated = $theme->getCfg('product_page/replace_related');
if ($replaceRelated == 1) //don't replace with static block
{
if ($tmpHtml = trim($this->getChildHtml('catalog.product.related')))
$section['related'] = $tmpHtml;
//$section['related'] = trim($this->getChildHtml('catalog.product.related'));
}
elseif ($replaceRelated == 2) //if related is empty, replace with static block
{
if ($tmpHtml = trim($this->getChildHtml('catalog.product.related')))
$section['related'] = $tmpHtml;
else //related empty
if ($tmpHtml = $this->getChildHtml('block_product_replace_related'))
$section['related'] = '<div class="block_product_replace_related">'. $tmpHtml .'</div>';
}
elseif ($replaceRelated == 3) //replace with static block
{
if ($tmpHtml = $this->getChildHtml('block_product_replace_related'))
$section['related'] = '<div class="block_product_replace_related">'. $tmpHtml .'</div>';
}
//Up-sell products. $section['upsell'] is set only if up-sell products (or replacement) exist
$replaceUpsell = $theme->getCfg('product_page/replace_upsell');
if ($replaceUpsell == 1) //don't replace with static block
{
if ($tmpHtml = trim($this->getChildHtml('upsell_products')))
$section['upsell'] = $tmpHtml;
//$section['upsell'] = $this->getChildHtml('upsell_products');
}
elseif ($replaceUpsell == 2) //if upsell is empty, replace with static block
{
if ($tmpHtml = trim($this->getChildHtml('upsell_products')))
$section['upsell'] = $tmpHtml;
else //upsell empty
if ($tmpHtml = $this->getChildHtml('block_product_replace_upsell'))
$section['upsell'] = '<div class="block_product_replace_upsell">'. $tmpHtml .'</div>';
}
elseif ($replaceUpsell == 3) //replace with static block
{
if ($tmpHtml = $this->getChildHtml('block_product_replace_upsell'))
$section['upsell'] = '<div class="block_product_replace_upsell">'. $tmpHtml .'</div>';
}
//Assign related products to selected position
if (isset($section['related']))
{
$relatedPosition = $theme->getCfg('product_page/related_position');
//TODO:remove: $relatedPosition = 11;
switch ($relatedPosition)
{
case 10:
$p['secondaryCol'][0] = $section['related'];
break;
case 11:
$p['secondaryCol'][1] = $section['related'];
break;
case 20:
$p['collatSecondaryCol'] = $section['related'];
break;
}
}
//Width (in grid units) of product page sections
$imgColUnits = $theme->getCfg('product_page/image_column');
$primaryColUnits = $theme->getCfg('product_page/primary_column');
$secondaryColUnits = $theme->getCfg('product_page/secondary_column');
$container2ColUnits = $imgColUnits + $primaryColUnits;
$collatPrimaryColUnits = $imgColUnits + $primaryColUnits;
$collatSecondaryColUnits = $secondaryColUnits;
//If no secondary column
if (empty($secondaryColUnits))
{
$primaryColUnits += 12 - ($imgColUnits + $primaryColUnits);
$container2ColUnits = $imgColUnits + $primaryColUnits;
$collatPrimaryColUnits = 9;
$collatSecondaryColUnits = 3;
}
//If no related products, stretch collateral primary column
if (!isset($section['related']))
{
$container2ColUnits = 12;
$collatPrimaryColUnits = 12;
$collatSecondaryColUnits = 0;
}
elseif (!isset($p['secondaryCol']))
{
$container2ColUnits = 12;
}
//Grid classes
$imgColGridClass = 'grid12-' . $imgColUnits;
$primaryColGridClass = 'grid12-' . $primaryColUnits;
$secondaryColGridClass = 'grid12-' . $secondaryColUnits;
$container2ColGridClass = 'grid12-' . $container2ColUnits;
$collatPrimaryColGridClass = 'grid12-' . $collatPrimaryColUnits;
$collatSecondaryColGridClass = 'grid12-' . $collatSecondaryColUnits;
if (empty($secondaryColUnits))
{
$secondaryColGridClass = '';
}
?>
<div class="product-img-column <?php echo $imgColGridClass; ?>">
<?php echo $this->getChildHtml('media') ?>
<?php //Product labels
echo $this->helper('ultimo/labels')->getLabels($_product);
?>
</div>
<div class="product-shop <?php echo $primaryColGridClass; ?>">
<div class="product-name">
<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
</div>
<?php echo $this->getReviewsSummaryHtml($_product, false, true); //reviews ?>
<?php if ($_product->getShortDescription()): ?>
<div class="short-description">
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>
<?php if ($theme->getCfg('product_page/sku')): ?>
<div class="sku"><span><?php echo $this->__('SKU'); ?>: </span><?php echo $_product->getSku(); ?></div>
<?php endif; ?>
<?php if ($extrahint_html = $this->getChildHtml('extrahint')): //qty increments ?>
<div class="extrahint-wrapper"><?php echo $extrahint_html; ?></div>
<?php endif; ?>
<div class="product-type-data<?php echo $productTypeClasses; ?>"><?php echo $this->getChildHtml('product_type_data'); ?></div>
<?php echo $this->getTierPriceHtml(); //tier prices ?>
<?php if (!$this->hasOptions()): //add to cart when no options ?>
<?php if($_product->isSaleable()): ?>
<div class="add-to-box">
<?php echo $this->getChildHtml('addtocart') ?>
</div>
<?php endif; ?>
<?php echo $this->getChildHtml('extra_buttons') ?>
<?php endif; ?>
<?php if ($_product->isSaleable() && $this->hasOptions()): ?>
<?php if ($container1_html = $this->getChildChildHtml('container1', '', true, true)): ?>
<div class="container1-wrapper"><?php echo $container1_html; ?></div>
<?php endif; ?>
<?php endif;?>
<?php if ($addtoLinksHtml = $this->getChildHtml('addto')): //compare, wishlist, to friend ?>
<div class="action-box clearer">
<?php echo $addtoLinksHtml; ?>
</div>
<?php endif; ?>
<?php echo $this->getChildHtml('alert_urls'); //alerts ?>
<?php echo $this->getChildHtml('other'); ?>
<?php if ($tmpHtml = $this->getChildHtml('block_product_primary_bottom')): ?>
<div class="feature-wrapper top-border block_product_primary_bottom"><?php echo $tmpHtml; ?></div>
<?php endif; ?>
<?php if ($tmpHtml = $this->getChildHtml('product_primary_bottom_placeholder')): //Placeholder for extensions ?>
<div class="feature-wrapper top-border"><?php echo $tmpHtml; ?></div>
<?php endif; ?>
</div> <!-- end: product-shop -->
<?php if ($secondaryColUnits): //(!empty($secondaryColUnits)): ?>
<div class="product-secondary-column <?php echo $secondaryColGridClass; ?> custom-sidebar-right">
<div class="inner">
<?php //Placeholder for extensions ?>
<?php if ($tmpHtml = $this->getChildHtml('product_secondary_top_placeholder')): //Placeholder for extensions ?>
<div class="margin-bottom"><?php echo $tmpHtml; ?></div>
<?php endif; ?>
<?php if (isset($p['secondaryCol'][0])): ?>
<?php echo $p['secondaryCol'][0]; ?>
<?php endif; ?>
<?php if ($tmpHtml = $this->getChildHtml('block_product_secondary_bottom')): ?>
<div class="feature-wrapper top-border block_product_secondary_bottom"><?php echo $tmpHtml; ?></div>
<?php endif; ?>
<?php if (isset($p['secondaryCol'][1])): ?>
<div class="margin-top"><?php echo $p['secondaryCol'][1]; ?></div>
<?php endif; ?>
<?php /*?>
<?php if (isset($section['related'])): ?>
<div class="margin-top"><?php echo $section['related']; ?></div>
<?php endif; ?>
<?php */?>
</div>
</div> <!-- end: product-secondary-column -->
<?php endif; ?>
<?php if ($_product->isSaleable() && $this->hasOptions()): ?>
<?php if ($container2_html = $this->getChildChildHtml('container2', '', true, true)): ?>
<div class="box-additional <?php echo $container2ColGridClass; ?>">
<div class="container2-wrapper"><?php echo $container2_html; ?></div>
</div>
<?php endif; ?>
<?php endif; ?>
</form>

If statement to not show div / h2

This for each / if statement displays changes, and then right below it it displays the changes made.
I am trying to write an if statement that tells it not to show the h2 and the #change_box if there are no changes.
Help would be greatly appreciated.
<h2 class="changes"> Changes: </h2>
<div id="change_box">
<? foreach ($audit['Events'] as $event):?>
<?if ( $event['Type'] != 'Comment'):?>
<span class="field">
<?= $event['Field']?>
</span>:
<?= $event['Value'] ?>
<?=($event['Previous'])?>
<?endif?>
<?endforeach?>
</div>
<?php
if ($changes) { // You'll have to set this variable
//Echo all of your HTML
else {
//Echo the stuff you'd rather show if they didn't change anything
}
?>
To give you an idea of how I'd write your code
<?php
if ($changes) {
echo '<h2 class="changes">Changes:</h2>';
echo '<div id="change_box">';
foreach ($audit['Events'] as $event) {
if ($event['Type'] != 'Comment') {
echo $event['Field'] . </span> . $event['Value'] . $event['Previous'];
}
}
echo "</div>"
}
?>
You could wrap your code with an if like
if(count($audit['Events'])>0)
{
//Your code
}
Wny do you open and close php tags every time? Would be better to make everything in PHP and echo whenever you want to print HTML code.
<?php
echo "<h2 class=\"changes\"> Changes: </h2>";
echo "<div id=\"change_box\">";
foreach ($audit['Events'] as $event) {
if ( $event['Type'] != 'Comment') {
echo "<span class=\"field\">".$event['Field']."</span>";
echo $event['Value'];
echo "(".$event['Previous'] .")";
}
}
echo "</div>";
?>
please make space after each <? and make sure you enabled short tags
<?php if(is_array($audit['Events']) && $audit['Events']):?>
<h2 class="changes"> Changes: </h2>
<div id="change_box">
<?php foreach ($audit['Events'] as $event):?>
<?php if ( $event['Type'] != 'Comment'):?>
<span class="field">
<?php echo $event['Field'];?>
</span>:
<?php echo $event['Value']; ?>
<?php echo $event['Previous'];?>
<?php endif;?>
<?php endforeach;endif;?>
</div>

Categories