Page goes blank after adding to PHP foreach - php

Hello after I add some code to this PHP foreach the page goes blank and all I can see is a round black dot at the top left of screen.
My website is in Joomla3 and I am trying to customize a module. my site is http://get2gethersports.com
I have a recent post module that only shows the articles title.
that code is posted below
<?php if ($items) { ?>
<ul class="rsblog-recent-module unstyled<?php echo $params->get('moduleclass_sfx',''); ?>">
<?php foreach ($items as $item) { ?>
<li>
<a <?php echo $opener; ?> href="<?php echo JRoute::_('index.php?option=com_rsblog&view=post&id='.RSBlogHelper::sef($item->id,$item->alias).$Itemid,false); ?>">
<?php echo $item->title; ?>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>
I would like to add an image abocve like the blog feed on http://vape-co.com
So I navigated to the component and saw the call for the image. which is posted below:
<div class="rsblog-entry-content">
<?php if ($this->item->image) { ?>
<div class="rsblog-entry-image">
<img class="rsblog-entry-thumb img-polaroid" src="<?php echo JURI::root().'components/com_rsblog/assets/images/blog/'.$this->item->image; ?>?nocache=<?php echo uniqid(''); ?>" alt="<?php echo $this->escape($this->item->title); ?>">
</div>
<?php } ?>
but whenever i add it or a snippet of it to the previous code it breaks....
Any ideas why it is breaking the page and how to fix it?
I tried adding in new li tags. Just adding the PHP part above the a link etc...
CODE UPDATE----
<?php if ($items) { ?>
<ul class="rsblog-recent-module unstyled<?php echo $params->get('moduleclass_sfx',''); ?>">
<?php foreach ($items as $item) { var_dump($item);?>
<li>
<div class="rsblog-entry-content">
<?php if ($this->item->image) { ?>
<div class="rsblog-entry-image">
<img class="rsblog-entry-thumb img-polaroid" src="<?php echo JURI::root().'components/com_rsblog/assets/images/blog/'.$this->item->image; ?>?nocache=<?php echo uniqid(''); ?>" alt="<?php echo $this->escape($this->item->title); ?>">
</div>
</div>
<?php } ?>
<a <?php echo $opener; ?> href="<?php echo JRoute::_('index.php?option=com_rsblog&view=post&id='.RSBlogHelper::sef($item->id,$item->alias).$Itemid,false); ?>">
<?php echo $item->title; ?>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>

Try $item->image instead of $this->item->image

Correct code. Looks like it just needed some reduction.
<?php if ($items) { ?>
<ul class="rsblog-recent-module unstyled<?php echo $params -> get('moduleclass_sfx',''); ?>">
<?php foreach ($items as $item) { ?>
<li>
<?php if($item->image != '') ?>
<img src="components/com_rsblog/assets/images/blog/<?php echo $item->image;?>" alt="<?php echo $item->title. "logo";?>" width="100px"/>
<br/>
<a <?php echo $opener; ?> href="<?php echo JRoute::_('index.php?option=com_rsblog&view=post&id='.RSBlogHelper::sef($item->id,$item->alias).$Itemid,false); ?>">
<?php echo $item->title; ?>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>

Related

Echo ACF color picker value inside foreach loop for WP tags

I have a foreach loop to display all the tags of my project. Each Tag must have a colour associated with it, and I am using ACF to create this field on the tags dashboard.
However, when I try to display the value from color picker inside my foreach loop it just doesn't work.
I just can't see what I am doing wrong.
Here is my php code:
<?php
$tagslist = get_tags();
foreach($tagslist as $tag) {
?>
<li>
<p><?php echo get_field('tag_color'); ?></p>
<a class="tag-list_item theme-<?php echo $tag->slug; ?>" data-tag="<?php echo $tag->term_id; ?>" href="<?php echo get_tag_link($tag->term_id); ?>" stye>
<?php echo $tag->name; ?>
</a>
</li>
<?php }
?>
The name of the field that I made is "tag_color".
You can use below code to get field from tags:
<?php
$tagslist = get_tags();
foreach($tagslist as $tag) {
?>
<li>
<p><?php echo get_field('tag_color', 'post_tag_'.$tag->term_id); ?></p>
<a class="tag-list_item theme-<?php echo $tag->slug; ?>" data-tag="<?php echo $tag->term_id; ?>" href="<?php echo get_tag_link($tag->term_id); ?>" stye>
<?php echo $tag->name; ?>
</a>
</li>
<?php } ?>
Below is the reference link:
https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

PHP foreach - Creating multple searchs in the same page

Firstly, I am a total php newby.
Secondly, below is the php header plus corresponding recursive commands for 2 photo lightboxes that are in the same html page.
Without the lines
getRecords() as $Title_row){ ?>
The page shows shows the first picture that is held in the external db table in the lightbox correctly.
Yet when I add the line below to add all the other entries in each table
getRecords() as $Title_row){ ?>
the page goes white and the browser html return is empty.
As I do not really understand what I am doing, I am stuck. Any suggestions would be very welcome.
<?php
$Title_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title_findCriterions = array('Order_web'=>'*',);
foreach($Title_findCriterions as $key=>$value) {
$Title_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title_find,'Title',50);
$Title_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title_result = $Title_find->execute();
if(FileMaker::isError($Title_result)) fmsTrapError($Title_result,"error.php");
fmsSetLastPage($Title_result,'Title',50);
$Title_row = current($Title_result->getRecords());
?>
<?php
$Title1_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title1_findCriterions = array('Order_web'=>'*',);
foreach($Title1_findCriterions as $key=>$value) {
$Title1_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title1_find,'Title',50);
$Title1_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title1_result = $Title1_find->execute();
if(FileMaker::isError($Title1_result)) fmsTrapError($Title1_result,"error.php");
fmsSetLastPage($Title1_result,'Title',50);
$Title1_row = current($Title1_result->getRecords());
?>
<!DOCTYPE html>
<!-- Lightbox Gallery -->
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<!-- Lightbox Gallery End-->
You just missed out the closing brackets :
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>

Trying to get str_replace working in custom Magento code

Here is my code:
<?php
$_rtl = Mage::getStoreConfig('custom_menu/general/rtl') + 0;
$_categories = $this->getStoreCategories();
if (is_object($_categories)) $_categories = $this->getStoreCategories()->getNodes();
?>
<div class="nav-container">
<div style="z-index:999;position:relative;top:-8px;left:979px;cursor:pointer;"><img src="<?php echo $this->getSkinUrl('images/Truck-Prince-text.png'); ?>" height="91" width="123" style="position:absolute;" onclick="location.href='<?php echo Mage::getUrl('checkout/cart'); ?>'"></div>
<div id="custommenu" class="<?php echo $_rtl ? ' rtl' : ''; ?>">
<?php if ($this->showHomeLink()) : ?>
<div class="menu">
<div class="parentMenu menu0">
<a href="<?php echo $this->getUrl('') ?>">
<span><?php echo $this->__('Home'); ?></span>
</a>
</div>
</div>
<?php endif ?>
<?php foreach ($_categories as $_category): ?>
<?php echo $this->drawCustomMenuItem($_category) ?>
<?php endforeach ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('nav-links-after')->toHtml() ?>
<div class="clearBoth"></div>
</div>
</div>
What I want to do is something like this but I don't know how to insert this in without causing errors. I basically want to change the existing url with the string replaced urls..
<?php // We must replace URLs on the fly to use landing pages and not break subcat navigation
$_category = str_replace('wild-bird-feed-supplies.html', 'landing-wild-bird-feed-supplies', $_category);
$_category = str_replace('lawn-garden-supplies.html', 'landing-lawn-garden-supplies', $_category);
$_category = str_replace('pet-food-supplies.html', 'landing-pet-food-supplies', $_category);
$_category = str_replace('animal-feed-supplies.html', 'landing-animal-feed-supplies', $_category); ?>
I finally was able to get it :) Here is what I did...
<?php
$_rtl = Mage::getStoreConfig('custom_menu/general/rtl') + 0;
$_categories = $this->getStoreCategories();
if (is_object($_categories)) $_categories = $this->getStoreCategories()->getNodes();
?>
<div class="nav-container">
<div style="z-index:999;position:relative;top:-8px;left:979px;cursor:pointer;"><img src="<?php echo $this->getSkinUrl('images/Truck-Prince-text.png'); ?>" height="91" width="123" style="position:absolute;" onclick="location.href='<?php echo Mage::getUrl('checkout/cart'); ?>'"></div>
<div id="custommenu" class="<?php echo $_rtl ? ' rtl' : ''; ?>">
<?php if ($this->showHomeLink()) : ?>
<div class="menu">
<div class="parentMenu menu0">
<a href="<?php echo $this->getUrl('') ?>">
<span><?php echo $this->__('Home'); ?></span>
</a>
</div>
</div>
<?php endif ?>
<?php foreach ($_categories as $_category): ?>
<?php $_category = $this->drawCustomMenuItem($_category) ?>
<?php // We must replace URLs on the fly to use landing pages and not break subcat navigation
$_category = str_replace('wild-bird-feed-supplies.html', 'landing-wild-bird-feed-supplies', $_category);
$_category = str_replace('lawn-garden-supplies.html', 'landing-lawn-garden-supplies', $_category);
$_category = str_replace('pet-food-supplies.html', 'landing-pet-food-supplies', $_category);
$_category = str_replace('animal-feed-supplies.html', 'landing-animal-feed-supplies', $_category); ?>
<?php echo $_category; ?>
<?php endforeach ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('nav-links-after')->toHtml() ?>
<div class="clearBoth"></div>
</div>
</div>

generating links dynamically

so i guess this is pretty easy for most of you, but i can't figure this out.
im trying to make the links dynamic eg: href="linkname(#1 or #2 etc)"
any ideas?
<?php if ($top_fundraisers && is_array($top_fundraisers)): ?>
<?php foreach ($top_fundraisers as $index => $fundraiser): ?>
<a title="" class="fancybox" href="linkname(GENERATE CODE HERE)">
<div class="top-fundraiser">
<div id="newo<?php print htmlentities($index + 1); ?>" class="top-fundraiser-image">
<img src="<?php
if($fundraiser['member_pic_medium']) {
print htmlentities($fundraiser['member_pic_medium']);
} else {
print $template_dir . '/images/portrait_placeholder.png';
}
?>"/>
</div>
</div>
</a>
<?php endforeach;?>
<?php endif; ?>
Suppose below is what you need.
<?php if ($top_fundraisers && is_array($top_fundraisers)): ?>
<?php foreach ($top_fundraisers as $index => $fundraiser): ?>
<a title="" class="fancybox" href="linkname(#<?php echo $index + 1; ?>)">
<div class="top-fundraiser">
<div id="newo<?php print htmlentities($index + 1); ?>" class="top-fundraiser-image">
<img src="<?php
if($fundraiser['member_pic_medium']) {
print htmlentities($fundraiser['member_pic_medium']);
} else {
print $template_dir . '/images/portrait_placeholder.png';
}
?>"/>
</div>
</div>
</a>
<?php endforeach;?>
<?php endif; ?>

Create a dynamic XML href in PHP with SimpleXML

I'm trying to create a link based on a URL variable using only the last five digits of its respective line of XML data.
For example, if the XML link is http://events.stanford.edu/events/213/21389 how can I create this link a href="e/?i=21389?
Here's my page, XML and code:
<?php
// Build the XML file path, using URL variable $c (above)
$c = $_GET['c'];
$p ="http://events-prod.stanford.edu/xml/byCategory/";
$e = "/mobile.xml";
$file = "$p$c$e";
$xml = simplexml_load_file($file);
?>
<h1><?php echo $xml->title; ?></h1>
Home
</div><!-- /header -->
<div data-role="content">
<?php // Only display if there are events ?>
<?php if (isset($xml->Event->title)) { ?>
<ul data-role="listview">
<?php foreach($xml->Event as $event) { ?>
<li>
<a href="<?php echo $event->link; ?>">
<?php if ($event->Media->url != null) { ?>
<img src="<?php echo $event->Media->url;?>" alt="<?php echo $event->title;?> thumbnail" />
<?php } ?>
<h3><?php echo $event->title; ?></h3>
<p><strong><?php echo $event->beginDate; ?> at <?php echo $event->beginTime; ?></strong></p>
<p><?php echo $event->locationText; ?></p>
</a>
</li>
<?php } ?>
</ul>
<?php } else { ?>
<?php echo '<p>There is currently nothing scheduled for ', $xml->title, '.</p>';?>
<?php } ?>
I'm using short tags, because I think you'll agree it's easier now to read the code as oppose to before.
<?
$controller ="http://events-prod.stanford.edu/xml/byCategory/";
$category_id = $_GET['c'];
$category_id = 0;
$xml = "/mobile.xml";
$url = $controller . $category_id . $xml;
$xml_object = simplexml_load_file($url);
?>
<div>
<h1><?= $xml_object->title ?></h1>
Home
</div>
<div data-role="content">
<? if (!empty($xml_object->Event->title)): ?>
<ul data-role="listview">
<? foreach($xml_object->Event as $event): ?>
<li>
<?
$pattern = '/[0-9]+$/';
$matches = array();
preg_match($pattern, $event->link, $matches);
$my_link = 'e/?i=' . $matches[0];
?>
<a href="<?= $my_link ?>">
<? if (!empty($event->Media->url)): ?>
<img src="<?= $event->Media->url ?>" alt="<?= $event->title ?> thumbnail" />
<? endif; ?>
<h3><?= $event->title ?></h3>
<p><strong><?= $event->beginDate ?> at <?= $event->beginTime ?></strong></p>
<p><?= $event->locationText ?></p>
</a>
</li>
<? endforeach; ?>
</ul>
<? else: ?>
<? echo '<p>There is currently nothing scheduled for ', $xml_object->title, '.</p>'; ?>
<? endif; ?>
</div>

Categories