I didn't build this PHP file, but I am trying to figure out why it is giving me errors. If the "Block layout mode" ACF variable is set to "Modal" then the block works, but gives me this error. "Undefined variable $vids on line 176". If I select the "Embed & Thumbnail" mode, then none of the block is displayed and I get this error. "Call to undefined function vc_embed_layout() on line 252". I can't pin down why this is happening, and I haven't been able to find any unclosed tags or anything in my php file. This is the file in question, and I've marked the lines that trigger errors.
<?php
global $theme_text_domain;
$block_class_identifier = 'blk__vidcol';
// default variables
$block_id = $top_class = $top_style = $inner_class = $inner_style = '';
// check for custom id
$block_id .= BLOCK::set_id( get_sub_field('content_block_id') );
// set block class, $i comes from FLEX class loop and represents the block order on a page
$top_class .= BLOCK::set_standard_classes( $i );
$top_class .= BLOCK::set_custom_classes( get_sub_field('content_block_classes') );
// check for top padding adjustment
$top_class .= BLOCK::set_padding_class( get_sub_field('block_padding_adjustment') );
$top_style .= BLOCK::set_padding_style( get_sub_field('block_padding_adjustment'), get_sub_field('custom_top_padding'), get_sub_field('custom_bottom_padding'));
// check for custom color theme
$top_style .= BLOCK::set_colors( get_sub_field('color_theme'), get_sub_field('text_color'), get_sub_field('custom_background_color') );
// check for width settings
$inner_class .= BLOCK::set_width_class( get_sub_field('content_width') );
$inner_style .= BLOCK::set_width_style( get_sub_field('content_width'), get_sub_field('custom_maximum_content_width') );
$block_assets = get_stylesheet_directory_uri() . '/inc/blocks/' . basename(__FILE__, '.php') . '/assets/';
/*
CUSTOM BLOCK SPECIFIC SETUP
*/
$layout = get_sub_field('block_layout_mode');
$top_class .= ' layout-' . $layout;
// title color
$h2_style = (get_sub_field('color_theme') == 'custom') ? ' color: ' . get_sub_field('custom_title_color') . ';' : '';
/**
* outputs code for the modal version of the video collection block
* #return html output
*/
if (!function_exists('vc_modal_layout')) {
function vc_modal_layout() {
global $block_class_identifier;
$cta_label = get_sub_field('cta_label');
$counter = 0;
$cta = array(
'style' => get_sub_field('cta_style'),
'button_color' => get_sub_field('button_color'),
'button_text_color' => get_sub_field('button_color')
);
$cta_class = BLOCK::get_cta_style( $cta, '.' . $block_class_identifier . ' .button');
?>
<?php // list section ?>
<?php if( have_rows('videos') ): ?>
<div class="vid-container">
<?php while ( have_rows('videos') ) : the_row(); ?>
<?php if ($counter == 0): ?>
<div class="vid-featured">
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo get_sub_field('youtube_embed_code'); ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
<a class="vid_overlay" data-fancybox data-src="#<?php echo $block_class_identifier; ?>_vid_0" href="javascript:;"></a>
</div>
<!-- modal -->
<div id="<?php echo $block_class_identifier; ?>_vid_0" class="modal video-modal" style="display: none;">
<div class="modal-inner">
<h3><?php echo get_sub_field('video_title'); ?></h3>
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo get_sub_field('youtube_embed_code'); ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
</div>
<div class="vid-list">
<?php else: ?>
<div class="vid-item">
<div class="item-btn">
<a class="button <?php echo $cta_class; ?>" data-fancybox data-src="#<?php echo $block_class_identifier; ?>_vid_<?php echo $counter; ?>" href="javascript:;"><?php echo $cta_label; ?></a>
</div>
<div class="item-title"><?php echo get_sub_field('video_title'); ?></div>
</div>
<!-- modal -->
<div id="<?php echo $block_class_identifier; ?>_vid_<?php echo $counter; ?>" class="modal video-modal" style="display: none;">
<div class="modal-inner">
<h3><?php echo get_sub_field('video_title'); ?></h3>
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo get_sub_field('youtube_embed_code'); ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
<?php endif; ?>
<?php $counter++; ?>
<?php endwhile; ?>
</div>
</div>
<?php else: ?>
No videos defined.
<?php endif; ?>
<?
}
}
/**
* outputs code for the embed version of the video collection block
* #return html output
*/
if (!function_exists('vc_embed_layout')) {
function vc_embed_layout($vids, $i) {
?>
<?php if ( $vids ): ?> **this is line 176**
<div class="vid-container2">
<h2 class="vid-title"><?php echo $vids[0]['video_title']; ?></h2>
<div class="vid-container2-inner">
<div class="vid-embed">
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo $vids[0]['youtube_embed_code']; ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen onload="this.style.visibility = 'visible';"></iframe>
</div>
</div>
<div class="vid-thumbnails">
<?php foreach ($vids as $key => $vid): ?>
<?php $wrap_class = ($key == 0) ? ' tn-hide' : ''; ?>
<div class="tn-wrapper <?php echo $wrap_class; ?>" data-embed="<?php echo $vid['youtube_embed_code']; ?>" data-title="<?php echo $vid['video_title']; ?>">
<img src="https://img.youtube.com/vi/<?php echo $vid['youtube_embed_code']; ?>/mqdefault.jpg" alt="">
</div>
<?php endforeach; ?>
</div>
</div>
<script>
var vid_swap = function() {
$('.block_<?php echo $i; ?> .vid-embed').css({opacity: 1});
$('.block_<?php echo $i; ?> .tn-wrapper').on('click', function(e) {
var $this = $(this);
var embed_id = $this.attr('data-embed');
var title = $this.attr('data-title');
console.log('embed = ' + embed_id);
$('.block_<?php echo $i; ?> .vid-title').animate({opacity: 0}, 100);
$('.block_<?php echo $i; ?> .vid-embed').animate({opacity: 0}, 1000, function() {
$('.block_<?php echo $i; ?> .vid-embed, .block_<?php echo $i; ?> .vid-title').css('visiblity','hidden');
$('.block_<?php echo $i; ?> .vid-title').html( title );
$('.block_<?php echo $i; ?> .vid-embed iframe').attr('src', 'https://www.youtube.com/embed/' + embed_id);
$('.block_<?php echo $i; ?> .tn-wrapper.tn-hide').removeClass('tn-hide');
$this.addClass('tn-hide');
$('.block_<?php echo $i; ?> .vid-title').css('visiblity','visible').delay(500).animate({opacity: 1}, 500);
$('.block_<?php echo $i; ?> .vid-embed').delay(500).animate({opacity: 1}, 1000);
});
});
}
jQuery(document).on('block_init', vid_swap);
</script>
</div>
<?php else: ?>
No videos defined.
<?php endif; ?>
<?php
}
}
?>
<section id="<?php echo $block_id; ?>" class="<?php echo $block_class_identifier; ?> <?php echo $top_class; ?>" style="<?php echo $top_style; ?>">
<div class="inner <?php echo $inner_class; ?>" style="<?php echo $inner_style; ?>">
<?php // title section ?>
<?php if (get_sub_field('title')): ?>
<h2 style="<?php echo $h2_style; ?>"><?php echo get_sub_field('title'); ?></h2>
<?php endif; ?>
<?php $vids = get_sub_field('videos'); ?>
<?php if ($layout == 'modal') vc_modal_layout($vids); ?>
<?php if ($layout == 'embed') vc_embed_layout($vids, $i); ?> **This is line 252**
</div>
</section>
You're not accepting any arguments in vc_modal_layout() function declaration.
if (!function_exists('vc_embed_layout')) {
function vc_embed_layout() {
needs to have parameters in order to accept arguments.
something like this is what you're looking for:
if (!function_exists('vc_embed_layout')) {
function vc_embed_layout($vids=[], $i=0) {
And it's the same idea with vc_modal_layout, the function needs to be able to accept the variables from outside it.
When we call a function, the function needs to be able to accept all arguments passed to it. And all variables we use need to be defined, if there's a risk of them being undefined or empty arrays, we can check them with if(!empty($var)) or if(isset($var))
An alternative to passing the variable to the function is to access it as a global. But it's generally better to pass the variable to the function because when we pass the variable to a function in PHP it works with a copy of the variable's value inside the function. When we do something like this:
$var = 10;
function doIt(){
global $var;
$var++;
}
doit();
echo $var;
we could overcomplicate things..
let's have a closer look here:
if ($layout == 'modal') vc_modal_layout($vids);
if ($layout == 'embed') vc_embed_layout($vids, $i); ?> **This is line 252**
function vc_modal_layout(){ ... }
// should be:
function vc_modal_layout($vids){ ... }
function vc_embed_layout($vids, $i)
// looks good.
Aside from that, nothing stands out as really unusual & I'd want to have a look at the actual site to tinker with this problem further.
Related
first off, I'm extremely new to PHP.
I'm using Conrete5, and I have a new template to an image slider. This is what I'm using:
http://codepen.io/altitudems/pen/KdgGLG
There's a placeholder image, which I'm trying to replace by grabbing the first image set in the block itself. Here is my view file from the actual block:
<?php defined('C5_EXECUTE') or die("Access Denied.");
$navigationTypeText = ($navigationType == 0) ? 'arrows' : 'pages';
$c = Page::getCurrentPage();
if ($c->isEditMode()) { ?>
<div class="ccm-edit-mode-disabled-item" style="width: <?php echo $width; ?>; height: <?php echo $height; ?>">
<div style="padding: 40px 0px 40px 0px"><?php echo t('Image Slider disabled in edit mode.')?></div>
</div>
<?php } else { ?>
<script>
$(document).ready(function(){
$(function () {
$("#ccm-image-slider-<?php echo $bID ?>").responsiveSlides({
prevText: "", // String: Text for the "previous" button
nextText: "",
<?php if($navigationType == 0) { ?>
nav:true
<?php } else { ?>
pager: true
<?php } ?>
});
});
});
</script>
<div class="ccm-image-slider-container ccm-block-image-slider-<?php echo $navigationTypeText?>" >
<div class="ccm-image-slider">
<div class="ccm-image-slider-inner">
<?php if(count($rows) > 0) { ?>
<ul class="rslides" id="ccm-image-slider-<?php echo $bID ?>">
<?php foreach($rows as $row) { ?>
<li>
<?php if($row['linkURL']) { ?>
<?php } ?>
<?php
$f = File::getByID($row['fID'])
?>
<?php if(is_object($f)) {
$tag = Core::make('html/image', array($f, false))->getTag();
if($row['title']) {
$tag->alt($row['title']);
}else{
$tag->alt("slide");
}
print $tag; ?>
<?php } ?>
<div class="ccm-image-slider-text">
<?php if($row['title']) { ?>
<h1 class="ccm-image-slider-title"><?php echo $row['title'] ?></h1>
<?php } ?>
<?php echo $row['description'] ?>
</div>
</li>
<?php } ?>
</ul>
<?php } else { ?>
<div class="ccm-image-slider-placeholder">
<p><?php echo t('No Slides Entered.'); ?></p>
</div>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
Here is my gallery view file:
<a class="gallery-launcher" href="#gallery1"> // Location of the image
<div class="overlay">
<div class="overlay-content">
<button class="btn btn-default">Open Gallery</button>
</div>
</div>
</a>
<div class="gallery inactive" id="gallery1">
<div class="gallery-item">
//Fullscreen gallery code here
</div>
</div>
Where it says // Location of the image is where I need to have the first image set. I can't figure out what I'd put there? Any help will be appreciated.
You could use the concrete5 file helper to get the file path, like this for example:
$f = File::getByID($row['fID']);
$relpath = $f->getRelativePath();
In general I suggest that you read more about the concrete5 file functions to understand more how it works:
I have a list of content that I would have a paging. Until now I was able to count correctly how content we are, then we have 3 content, and imposed a maximum of 2 applications per page, in my index shows the link to go to the next page.
Unfortunately, however, always displays the same content. For example:
http://i62.tinypic.com/156skjo.png
http://i60.tinypic.com/30xcy1l.png
However, I paste the current code, I hope you can help me out. Thank You
<?php require_once 'app/init.php'; ?>
<?php echo View::make('header')->render() ?>
<div class="row">
<!-- START MAIN GRID -->
<?php
// Create a variable imposed where the number of records
// To display on each page
$x_pag = 2;
// Retrieve the current page number.
// Usually you use a querystring
$pag = isset($_GET['pag']) ? $_GET['pag'] : 1;
// Check if $pag is valued and if numeric
// ... Otherwise I assign a value of 1
if (!$pag || !is_numeric($pag)) $pag = 1;
$quest = DB::table('questions')
->count();
// Using a simple mathematical operation define the total number of pages
$all_pages = ceil($quest / $x_pag);
// Calculation of which record start
$first = ($pag - 1) * $x_pag;
$questions = DB::table('questions')
->orderBy('id', 'desc')
->take($x_pag)
->get();
foreach ($questions as $question):
$user = User::find($question->user_id);
?>
<div class="col-md-4 col-lg-4">
<div class="main-grid">
<div class="profile-inner img-responsive" style="background-image: url('images/<?php echo $question->h_image; ?>');border-radius: 10px 10px 0px 0px;">
<img src="<?php echo $user->avatar; ?>" class="small-thumb" >
</div>
<div class="description">
<h5><strong><?php echo $question->user_name; ?></strong>
<?php if (Auth::check() && Auth::user()->id != $question->user_id): ?>
<?php $contact = Contact::find(Auth::user()->id, $question->user_id); ?>
<?php if (!empty($contact) && !empty($contact->accepted)): ?>
( <?php _e('main.remove_contact') ?> )
<?php elseif (!empty($contact)): ?>
( <a href="javascript:EasyLogin.removeContact(<?php echo $question->user_id ?>)" data-contact-id="<?php echo $question->user_id ?>" ><?php _e('main.cancel_contact') ?></a> )
<?php else: ?>
( <?php _e('main.add_contact') ?> )
<?php endif ?>
<?php endif ?>
</h5>
<h3><?php echo $question->h_title; ?>?</h3>
<hr />
Help +
</div>
</div>
</div>
<?php endforeach; ?>
<!-- MAIN GRID END -->
</div>
<?php
// If the total pages are more than 1 ...
// Mold the link to go back and forth between different pages!
if ($all_pages > 1){
if ($pag > 1){
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?pag=" . ($pag - 1) . "\">";
echo "Back</a> ";
}
if ($all_pages > $pag){
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?pag=" . ($pag + 1) . "\">";
echo "Next</a>";
}
}
?>
<?php echo View::make('footer')->render() ?>
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>
I have created some custom code (lines 287-309 in the code below)It is a duplicate function of 313-345 but with a few changes.
Although the function works perfectly well for some reason the page upon change or refresh duplicate the collection at the bottom of the page.
If I move lines 287-309 to line 347 onwards this does not happen. I'm assuming I a creating some sort of loop here or am I not closing the PHP correctly?
Any help would be hugely appreciated.
The Code:
<?php
include "../include/db.php";
include "../include/authenticate.php";
include "../include/general.php";
include "../include/resource_functions.php";
include "../include/collections_functions.php";
hook("homeheader");
include "../include/header.php";
if (!hook("replacehome")) {
if (!hook("replaceslideshow")) {
# Count the files in the configured $homeanim_folder.
$dir = dirname(__FILE__) . "/../" . $homeanim_folder;
$filecount = 0;
$checksum=0; # Work out a checksum which is the total of all the image files in bytes - used in image URLs to force a refresh if any of the images change.
$d = scandir($dir);
sort($d, SORT_NUMERIC);
$reslinks=array();
foreach ($d as $f) {
if(preg_match("/[0-9]+\.(jpg)/",$f))
{
$filecount++;
$checksum+=filesize($dir . "/" . $f);
$linkfile=substr($f,0,(strlen($f)-4)) . ".txt";
$reslinks[$filecount]="";
if(file_exists("../" . $homeanim_folder . "/" . $linkfile))
{
$linkref=file_get_contents("../" . $homeanim_folder . "/" . $linkfile);
$linkaccess = get_resource_access($linkref);
if (($linkaccess!=="") && (($linkaccess==0) || ($linkaccess==1))){$reslinks[$filecount]=$baseurl . "/pages/view.php?ref=" . $linkref;}
}
}
}
$homeimages=$filecount;
if ($filecount>1) { # Only add Javascript if more than one image.
?>
<script type="text/javascript">
var num_photos=<?php echo $homeimages?>; // <---- number of photos (/images/slideshow?.jpg)
var photo_delay=5; // <---- photo delay in seconds
var link = new Array();
<?php
$l=1;
foreach ($reslinks as $reslink)
{
echo "link[" . $l . "]=\"" . $reslink . "\";";
$l++;
}
?>
var cur_photo=2;
var last_photo=1;
var next_photo=2;
flip=1;
var image1=0;
var image2=0;
function nextPhoto()
{
if (!document.getElementById('image1')) {return false;} /* Photo slideshow no longer available (AJAX page move) */
if (cur_photo==num_photos) {next_photo=1;} else {next_photo=cur_photo+1;}
image1 = document.getElementById("image1");
image2 = document.getElementById("photoholder");
sslink = document.getElementById("slideshowlink");
linktarget=link[cur_photo];
if (flip==0)
{
// image1.style.visibility='hidden';
//Effect.Fade(image1);
jQuery('#image1').fadeOut(1000)
window.setTimeout("image1.src='<?php echo $baseurl . "/" . $homeanim_folder?>/" + next_photo + ".jpg?checksum=<?php echo $checksum ?>';if(linktarget!=''){jQuery('#slideshowlink').attr('href',linktarget);}else{jQuery('#slideshowlink').removeAttr('href');}",1000);
flip=1;
}
else
{
// image1.style.visibility='visible';
//Effect.Appear(image1);
jQuery('#image1').fadeIn(1000)
window.setTimeout("image2.style.background='url(<?php echo $baseurl . "/" . $homeanim_folder?>/" + next_photo + ".jpg?checksum=<?php echo $checksum ?>)';if(linktarget!=''){jQuery('#slideshowlink').attr('href',linktarget);}else{jQuery('#slideshowlink').removeAttr('href');}",1000);
flip=0;
}
last_photo=cur_photo;
cur_photo=next_photo;
timers.push(window.setTimeout("nextPhoto()", 1000 * photo_delay));
}
jQuery(document).ready( function ()
{
/* Clear all old timers */
ClearTimers();
timers.push(window.setTimeout("nextPhoto()", 1000 * photo_delay));
}
);
</script>
<?php } ?>
<div class="HomePicturePanel"
<?php if (isset($home_slideshow_width)) {
echo "style=\"";
$slide_width = $home_slideshow_width + 0;
echo"width:" . (string)$slide_width ."px; ";
echo "\" ";
}
?>>
<a id="slideshowlink"
<?php
$linkurl="#";
if(file_exists("../" . $homeanim_folder . "/1.txt"))
{
$linkres=file_get_contents("../" . $homeanim_folder . "/1.txt");
$linkaccess = get_resource_access($linkres);
if (($linkaccess!=="") && (($linkaccess==0) || ($linkaccess==1))) {$linkurl=$baseurl . "/pages/view.php?ref=" . $linkres;}
echo "href=\"" . $linkurl ."\" ";
}
?>
\>
<div class="HomePicturePanelIN" id='photoholder' style="
<?php
if (isset($home_slideshow_height)){
echo"height:" . (string)$home_slideshow_height ."px; ";
}
?>
background-image:url('<?php echo $baseurl . "/" . $homeanim_folder?>/1.jpg?checksum=<?php echo $checksum ?>');">
<img src='<?php echo $baseurl . "/" . $homeanim_folder?>/2.jpg?checksum=<?php echo $checksum ?>' alt='' id='image1' style="display:none;<?php
if (isset($home_slideshow_width)){
echo"width:" . $home_slideshow_width ."px; ";
}
if (isset($home_slideshow_height)){
echo"height:" . $home_slideshow_height ."px; ";
}
?>">
</div>
</a>
<div class="PanelShadow"></div>
</div>
<?php } # End of hook replaceslideshow
?>
<?php if (checkperm("s")) {
hook("homebeforepanels");
?>
<?php if ($home_themeheaders && $enable_themes) { ?>
<div class="HomePanel"><div class="HomePanelIN">
<h2><a onClick="return CentralSpaceLoad(this,true);" href="<?php echo $baseurl_short?>pages/themes.php"><?php echo $lang["themes"]?></a></h2>
<?php echo text("themes")?>
<br /> <br />
<select style="width:140px;" onChange="CentralSpaceLoad(this.value,true);">
<option value=""><?php echo $lang["select"] ?></option>
<?php
$headers=get_theme_headers();
for ($n=0;$n<count($headers);$n++)
{
?>
<option value="<?php echo $baseurl_short?>pages/themes.php?header=<?php echo urlencode($headers[$n])?>"><?php echo i18n_get_translated(str_replace("*","",$headers[$n]))?></option>
<?php
}
?>
</select>
<br />> <?php echo $lang["viewall"] ?>
</div>
<div class="PanelShadow"></div>
</div>
<?php } ?>
<?php if ($home_themes && $enable_themes) { ?>
<div class="HomePanel"><div class="HomePanelINtopA">
<div class="HomePanelINtopHeader"><?php echo $lang["themes"]?></div>
<div class="HomePanelINtopText"><?php echo text("themes")?></div>
</div>
<div class="PanelShadow"></div>
</div>
<?php } ?>
<?php if ($home_mycollections && !checkperm("b") && $userrequestmode!=2 && $userrequestmode!=3) { ?>
<div class="HomePanel"><div class="HomePanelINtopB">
<div class="HomePanelINtopHeader"> <?php echo $lang["mycollections"]?></div>
<div class="HomePanelINtopText"><?php echo text("mycollections")?></div>
</div>
<div class="PanelShadow">
</div>
</div>
<?php } ?>
<?php if ($home_advancedsearch) { ?>
<div class="HomePanel"><div class="HomePanelINtopC">
<div class="HomePanelINtopHeader"> <?php echo $lang["advancedsearch"]?></div>
<div class="HomePanelINtopText"><?php echo text("advancedsearch")?></div>
</div>
<div class="PanelShadow"></div>
</div>
<?php } ?>
<?php if ($home_mycontributions && (checkperm("d") || (checkperm("c") && checkperm("e0")))) { ?>
<div class="HomePanel"><div class="HomePanelINtopD">
<div class="HomePanelINtopHeader"><?php echo $lang["mycontributions"]?></div>
<div class="HomePanelINtopText"><?php echo text("mycontributions")?></div>
</div>
<div class="PanelShadow"></div>
</div>
<?php } ?>
<?php if ($home_helpadvice) { ?>
<div class="HomePanel"><div class="HomePanelINtopE">
<div class="HomePanelINtopHeader"><?php echo $lang["helpandadvice"]?></div>
<div class="HomePanelINtopText"><?php echo text("help")?></div>
</div>
<div class="PanelShadow"></div>
</div>
<?php } ?>
<?php if ($home_themes && $enable_themes) { ?>
<div class="HomePanel"><div class="HomePanelINtopIntro">
<div class="HomePanelINtopHeader"><?php echo text("welcometitle")?></div>
<div class="HomePanelINtopText"><?php echo text("welcometext")?></div>
</div>
<div class="PanelShadow"></div>
</div>
<?php } ?>
<?php
/* ------------ Customisable home page panels ------------------- */
if (isset($custom_home_panels))
{
for ($n=0;$n<count($custom_home_panels);$n++)
{
if (!hook("panelperm")) {
?>
<div class="HomePanel"><div class="HomePanelIN" <?php if ($custom_home_panels[$n]["text"]=="") {?>style="min-height:0;"<?php } ?>>
<h2><a href="<?php echo $custom_home_panels[$n]["link"] ?>" <?php if (isset($custom_home_panels[$n]["additional"])){ echo $custom_home_panels[$n]["additional"];} ?>> <?php echo i18n_get_translated($custom_home_panels[$n]["title"]) ?></a></h2>
<?php echo i18n_get_translated($custom_home_panels[$n]["text"]) ?>
</div>
<div class="PanelShadow"></div>
</div>
<?php
} // end hook 'panelperm'
}
}
?>
<!-- THIS IS LINE 287 please refer to question -->
<?php
if(!hook("EditorsPick")):
/* ------------ Collections promoted to the home page ------------------- */
$home_collectionsx=get_home_page_promoted_collectionsx(16);
foreach ($home_collectionsx as $home_collectionx)
{
?>
<div class="EditorsPick">
<div class="HomePanel"><div class="HomePanelINtopEditors">
<div class="HomePanelINtopHeader">Editors Pick</div>
<div class="HomePanelINtopText">This is the editors pick of Asset Space...</div>
<div class="EditorsPicImage"><div style="padding-top:<?php echo floor((155-$home_collectionx["thumb_height"])/2) ?>px; margin-top: -24px; margin-bottom: -15px;">
<a href="<?php echo $baseurl_short?>pages/search.php?search=!collection<?php echo $home_collectionx["ref"] ?>" onClick="return CentralSpaceLoad(this,true);"><img class="ImageBorder" src="<?php echo get_resource_path($home_collectionx["home_page_image"],false,"thm",false) ?>" width="<?php echo $home_collectionx["thumb_width"] ?>" height=" <?php echo $home_collectionx["thumb_height"] ?>" /></div>
</div></div>
</div>
</div>
</div>
<?php
}
endif; # end hook homefeaturedcol
?>
<!-- THIS IS LINE 309 please refer to question -->
<!-- THIS IS LINE 313 please refer to question -->
<?php
if(!hook("homefeaturedcol")):
/* ------------ Collections promoted to the home page ------------------- */
$home_collections=get_home_page_promoted_collections(16);
foreach ($home_collections as $home_collection)
{
?>
<div class="ResourceOfTheDay"></div>
<div class="HomePanel HomePanelPromoted"><div class="HomePanelIN HomePanelPromotedIN">
<div class="MyCollectionsHighlite"></div>
<div class="HomePanelPromotedImageWrap">
<div style="padding-top:<?php echo floor((155-$home_collection["thumb_height"])/2) ?>px; margin-top: -24px; margin-bottom: -15px;">
<a href="<?php echo $baseurl_short?>pages/search.php?search=!collection<?php echo $home_collection["ref"] ?>" onClick="return CentralSpaceLoad(this,true);"><img class="ImageBorder" src="<?php echo get_resource_path($home_collection["home_page_image"],false,"thm",false) ?>" width="<?php echo $home_collection["thumb_width"] ?>" height="<?php echo $home_collection["thumb_height"] ?>" /></div>
</div>
<p style="font-size:14px; font-weight:bold"><?php echo i18n_get_translated($home_collection["home_page_text"]) ?></p>
<p style="font-size:12px; font-weight:normal">Click to view this collection</p>
</div>
<div class="PanelShadow"></div>
</div>
<?php
}
endif; # end hook homefeaturedcol
?>
<!-- THIS IS LINE 345 please refer to question -->
<!-- THIS IS LINE 347 please refer to question -->
<div class="clearerleft"></div>
<?php }
} // End of ReplaceHome hook
include "../include/footer.php";
?>
From your comment above I would say this line is to blame:
if(!hook("homefeaturedcol")):
I'm assuming that this is running as well as your new code above it when it's not the homepage
You may also want to have a look at your HTML structure
This is a very difficult question to ask but, lets try. I am using this module for joomla i need tocreate an overide for it so that it takes the first result of
<?php foreach( $pages as $key => $list ): ?>
and places it in its own div and carries on with the statement. Please ask if any other information is needed here's the entire code for the override:
<?php
/**
* #package mod_bt_contentslider - BT ContentSlider Module
* #version 1.4
* #created Oct 2011
* #author BowThemes
* #email support#bowthems.com
* #website http://bowthemes.com
* #support Forum - http://bowthemes.com/forum/
* #copyright Copyright (C) 2012 Bowthemes. All rights reserved.
* #license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
if($modal){JHTML::_('behavior.modal');}
$document = JFactory::getDocument();
if(count($list)>0){?>
<div id="btcontentslider<?php echo $module->id; ?>" style="display:none;" class="span4 bt-cs<?php echo $moduleclass_sfx? ' bt-cs'.$params->get('moduleclass_sfx'):'';?>">
<!--CONTENT-->
<div class="slides_container" style="width:<?php echo $moduleWidth.";".$add_style;?>">
<?php foreach( $pages as $key => $list ): ?>
<div class="slide" style="width:100%;">
<?php foreach( $list as $i => $row ): ?>
<ul class="bt-row <?php if($i==0) echo 'bt-row-first'; else if($i==count($list)-1) echo 'bt-row-last' ?>" style="width:100%" >
<li class="bt-inner">
<?php if( $row->thumbnail && $align_image != "center"): ?>
<a target="<?php echo $openTarget; ?>" class="bt-image-link<?php echo $modal? ' modal':''?>" title="<?php echo $row->title;?>" href="<?php echo $modal?$row->mainImage:$row->link;?>">
<img <?php echo $imgClass ?> src="<?php echo $row->thumbnail; ?>" alt="<?php echo $row->title?>" style="width:<?php echo $thumbWidth ;?>px; float:<?php echo $align_image;?>;margin-<?php echo $align_image=="left"? "right":"left";?>:5px" title="<?php echo $row->title?>" />
</a>
<?php endif; ?>
<?php if( $showTitle ): ?>
<a class="bt-title" target="<?php echo $openTarget; ?>"
title="<?php echo $row->title; ?>"
href="<?php echo $row->link;?>"> <?php echo $row->title_cut; ?> </a><br />
<?php endif; ?>
<?php if( $row->thumbnail && $align_image == "center" ): ?>
<div class="bt-center">
<a target="<?php echo $openTarget; ?>"
class="bt-image-link<?php echo $modal? ' modal':''?>"
title="<?php echo $row->title;?>" href="<?php echo $modal?$row->mainImage:$row->link;?>">
<img <?php echo $imgClass ?> src="<?php echo $row->thumbnail; ?>" alt="<?php echo $row->title?>" style="width:<?php echo $thumbWidth ;?>px;" title="<?php echo $row->title?>" />
</a>
</div>
<?php endif ; ?>
<?php if( $show_intro ): ?>
<div class="bt-introtext">
<?php echo $row->description; ?>
</div>
<?php endif; ?>
<?php if( $showReadmore ) : ?>
<p class="readmore">
<a target="<?php echo $openTarget; ?>"
title="<?php echo $row->title;?>"
href="<?php echo $row->link;?>"> <?php echo JText::_('READ_MORE');?>
</a>
</p>
<?php endif; ?>
</li>
<!--end bt-inner -->
</ul>
<!--end bt-row -->
<!--CONTENT-->
<?php endforeach; ?>
<div style="clear: both;"></div>
</div>
<!--end bt-main-item page -->
<?php endforeach; ?>
</div>
<?php if( $next_back && $totalPages > 1 ) : ?>
<a class="prev" href="#"></a><a class="next" href="#"></a>
<?php endif; ?>
</div>
<!--end bt-container -->
<div style="clear: both;"></div>
<script type="text/javascript">
if(typeof(btcModuleIds)=='undefined'){var btcModuleIds = new Array();var btcModuleOpts = new Array();}
btcModuleIds.push(<?php echo $module->id; ?>);
btcModuleOpts.push({
slideEasing : '<?php echo $slideEasing; ?>',
fadeEasing : '<?php echo $slideEasing; ?>',
effect: '<?php echo $effect; ?>',
preloadImage: '<?php echo $preloadImg; ?>',
generatePagination: <?php echo $paging ?>,
play: <?php echo $play; ?>,
hoverPause: <?php echo $hoverPause; ?>,
slideSpeed : <?php echo $duration; ?>,
autoHeight:<?php echo $autoHeight ?>,
fadeSpeed : <?php echo $fadeSpeed ?>,
equalHeight:<?php echo $equalHeight; ?>,
width: <?php echo $moduleWidth=='auto'? "'auto'":$params->get( 'module_width', 0 ); ?>,
height: <?php echo $moduleHeight=='auto'? "'auto'":$params->get( 'module_height', 0 ); ?>,
pause: 100,
preload: true,
paginationClass: '<?php echo $butlet==1 ? 'bt_handles': 'bt_handles_num' ?>',
generateNextPrev:false,
prependPagination:true,
touchScreen:<?php echo $touchScreen ?>
});
</script>
<?php
// set position for bullet
if($butlet) {
$nav_top = (-1)*(int)$params->get( 'navigation_top', 0 );
$nav_right = (-1)*(int)$params->get( 'navigation_right', 0 )+5;
if(trim($params->get('content_title'))) $nav_top += 13;
$document->addStyleDeclaration(
$modid . ' ' . ($butlet == 1 ? '.bt_handles' : '.bt_handles_num') . '{'.
'bottom: ' . '5% !important;'.
'right: ' . '50% !important'.
'}'
);
}
// set responsive for mobile device
if($moduleWidth=='auto'){
$document->addStyleDeclaration(
'
#media screen and (max-width: 480px){.bt-cs .bt-row{width:100%!important;}}'
);
}
}
else
{
echo '<div>No result...</div>';
} ?>
Any Help Greatly apreciated.
you can do something like this. basicly, set a boolean to only do something different to the first item:
<?php $first = true; ?>
<?php foreach( $pages as $key => $list ): ?>
<?php
if($first) {
/* put this $list in its own div or whatever you need to do */
$first = false;
} else {
... //the default operation/code
?>
...
<?php } ?>
<?php endforeach; ?>
Complete Edit:
Use a counter to know which iteration it is:
<?php $c = 0; // initialize counter
foreach( $pages as $key => $list ):
if ($c++ == 0):
?>
this section will only run for the first element.
<?php endif;?>