joomla - PHP array not working correctly -
i having problem getting array work correctly. pulling params joomla template , using them on main index file: here have far:
this held in include file pull in first
//social icons $tbfacebook = $this->params->get('tbfacebook'); $tbtwitter = $this->params->get('tbtwitter'); $tbgoogle = $this->params->get('tbgoogle'); $tblinkedin = $this->params->get('tblinkedin'); $tbpinterest = $this->params->get('tbpinterest'); $tbyoutube = $this->params->get('tbyoutube'); $tbvimeo = $this->params->get('tbvimeo'); //check text boxes content , assign array info //this may able handled differently simplicity left lone if ($tbfacebook != null) { $arrfacebook= array("href" => $tbfacebook, "title" => "like on facebook", "icon" => "<i class=\"fa fa-facebook".$varsquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbtwitter != null) { $arrtwitter = array("href" => $tbtwitter , "title" => "follow on twitter", "icon" => "<i class=\"fa fa-twitter".$varsquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbgoogle != null) { $arrgoogle = array("href" => $tbgoogle , "title" => "follow on google plus", "icon" => "<i class=\"fa fa-google-plus".$varsquare." fa-2x\"></i>", "target" => "blank"); }; if ($tblinkedin != null) { $arrlinkedin = array("href" => $tblinkedin , "title" => "connect on linkedin", "icon" => "<i class=\"fa fa-linkedin".$varsquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbpinterest != null) { $arrpinterest = array("href" => $tbpinterest , "title" => "pin on pinterest", "icon" => "<i class=\"fa fa-pinterest".$varsquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbyoutube != null) { $arryoutube = array("href" => $tbyoutube , "title" => "watch on youtube", "icon" => "<i class=\"fa fa-youtube".$varsquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbvimeo != null) { $arrvimeo = array("href" => $tbvimeo , "title" => "watch on vimeo", "icon" => "<i class=\"fa fa-vimeo-square fa-2x\"></i>", "target" => "blank"); }; //create social array $arrsocial = array( $arrfacebook, $arrtwitter, $arrgoogle, $arrlinkedin, $arrpinterest, $arryoutube, $arrvimeo ); //remove empties foreach($arrsocial $key => $value) { if (empty($value)) { unset($arrsocial[$key]); $arrsocial = array_values($arrsocial); }; } //variable determine fist item, incase not phone $first = true;
my joomla code
<?php if ($this->countmodules('footer_mobile')) : ?> <jdoc:include type="modules" name="footer_mobile" style="html5" /> <?php else : //limit first 5 items for($i=0;$i<5;$i++){ if ( $first ) { $first = false; echo '<div class="col-xs-2 col-xs-offset-1"><a href="'.$arrmobilefooter[$i]["href"].'" title="'.$arrmobilefooter[$i]["title"].'" target="_'.$arrmobilefooter[$i]["target"].'" ">'.$arrmobilefooter[$i]["icon"].'</a></div>'; } else { echo '<div class="col-xs-2"><a href="'.$arrmobilefooter[$i]["href"].'" title="'.$arrmobilefooter[$i]["title"].'" target="_'.$arrmobilefooter[$i]["target"].'">'.$arrmobilefooter[$i]["icon"].'</a></div>'; }; }; endif; ?>
when file outputs pull in facebook link, though loop creating rest not populating it:
<div class="col-xs-2 col-xs-offset-1"> <a href="https://www.facebook.com/pages/united-methodist-camp-tekoa-inc/304907509358" title="like on facebook" target="_blank"> <i class="fa fa-facebook-square fa-2x"></i> </a> </div> <div class="col-xs-2"> <a href="/" title="" target="_" "=""></a> </div> <div class="col-xs-2"> <a href="/" title="" target="_"></a> </div> <div class="col-xs-2"> <a href="/" title="" target="_"></a> </div> <div class="col-xs-2"> <a href="/" title="" target="_"></a> </div>
can please tell me doing wrong?
i guess problem when trying manipulate $arrsocial
within foreach
. recommend rewrite , add together object array if aren't null
using $arrsocial[] = value
adding existing array.
try this:
//social icons $tbfacebook = $this->params->get('tbfacebook'); $tbtwitter = $this->params->get('tbtwitter'); $tbgoogle = $this->params->get('tbgoogle'); $tblinkedin = $this->params->get('tblinkedin'); $tbpinterest = $this->params->get('tbpinterest'); $tbyoutube = $this->params->get('tbyoutube'); $tbvimeo = $this->params->get('tbvimeo'); $arrsocial = array(); if ($tbfacebook != null) { $arrsocial[] = array("href" => $tbfacebook, "title" => "like on facebook", "icon" => "<i class=\"fa fa-facebook".$varsquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbtwitter != null) { $arrsocial[] = array("href" => $tbtwitter , "title" => "follow on twitter", "icon" => "<i class=\"fa fa-twitter".$varsquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbgoogle != null) { $arrsocial[] = array("href" => $tbgoogle , "title" => "follow on google plus", "icon" => "<i class=\"fa fa-google-plus".$varsquare." fa-2x\"></i>", "target" => "blank"); }; if ($tblinkedin != null) { $arrsocial[] = array("href" => $tblinkedin , "title" => "connect on linkedin", "icon" => "<i class=\"fa fa-linkedin".$varsquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbpinterest != null) { $arrpinterest = array("href" => $tbpinterest , "title" => "pin on pinterest", "icon" => "<i class=\"fa fa-pinterest".$varsquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbyoutube != null) { $arrsocial[] = array("href" => $tbyoutube , "title" => "watch on youtube", "icon" => "<i class=\"fa fa-youtube".$varsquare." fa-2x\"></i>", "target" => "blank"); }; if ($tbvimeo != null) { $arrsocial[] = array("href" => $tbvimeo , "title" => "watch on vimeo", "icon" => "<i class=\"fa fa-vimeo-square fa-2x\"></i>", "target" => "blank"); };
php joomla multidimensional-array joomla3.0
No comments:
Post a Comment