Javascript Yii: Session script - php

Okay, so basically whenever someone gets on the site the icons are all the same color (White) I want this code to do the follow thing : Whenever someone goes to another page (by clicking on one of the other icons) the icon of the page where he is going should have a different color (blue, this is done by loading another image) but only that page, this should also stay whenever he refreshes the page?
This is the current code that I have for a single icon, its not working yet and im not sure what is wrong..
<?php Yii::app()->session['/home'] = '1';
$home = Yii::app()->session['/home'];
//echo Yii::app()->session['home']; // Prints "value"
if (!empty($home)){ ?>
<a href="<?php echo $this->createUrl("/admin/survey/sa/index")."/home"; ?>">
<img src='<?php echo $sImageURL;?>home.png' alt='<?php $clang->eT("Default administration page");?>' width='<?php echo $iconsize;?>' height='<?php echo $iconsize;?>'/></a>
<?php
}
else{?>
<a href="<?php echo $this->createUrl("/admin/survey/sa/index")."/home1" ?>">
<img src='<?php echo $sImageURL;?>home1.png' alt='<?php $clang->eT("Default administration page");?>' width='<?php echo $iconsize;?>' height='<?php echo $iconsize;?>'/></a>
<?php
}
?>

I agree with Ivo; I think it would be best to do this using CSS classes. You would have the default CSS class have a background image of home1.png, and the blue one have a background image of home.png. If I were doing this, I would use CSS sprites as well.
But, working with what you've got. Here's one way to do it in Yii:
<?php
// Get the current URI
$currentUri = Yii::app()->request->requestUri;
if($currentUri == '/admin/survey/sa/index'){
?>
<a href="<?php echo $this->createUrl("/admin/survey/sa/index")."/home1" ?>">
<img src='<?php echo $sImageURL;?>home1.png' alt='<?php $clang->eT("Default administration page");?>' width='<?php echo $iconsize;?>' height='<?php echo $iconsize;?>'/>
</a>
<?php
}else{
?>
<a href="<?php echo $this->createUrl("/admin/survey/sa/index")."/home1" ?>">
<img src='<?php echo $sImageURL;?>home1.png' alt='<?php $clang->eT("Default administration page");?>' width='<?php echo $iconsize;?>' height='<?php echo $iconsize;?>'/>
</a>
<?php
}
?>
For your other icons you can then reuse the $currentUri variable. You don't need to set any sessions. When you refresh the page the icon will still remain colored.

Related

PHP if database has url echo URL using hyperlinked button

I am trying to see if a file in my database exists, and if it does, show that file as a hyperlinked button. The file is a URL. I am able to get the file to show accordingly, but the button shows even if there is no hyperlink. I have been researching everywhere to find out how I can echo the button only if there is a corresponding file but have had no luck. Just can get it right. Here is what I have and appreciate the help.
<?php if (file_exists($video))?><a class="videobutton" href="<?php echo $video; ?>"></a>
So based on Your Comment that you want to hide the whole button if the file is not found so this is how to do it :
<?php
if (file_exists($video)): ?>
<a class="videobutton" href="<?php echo $video; ?>"></a>
<?php endif; ?>
OR
if (file_exists($video)){ ?>
<a class="videobutton" href="<?php echo $video; ?>"></a>
<?php } ?>
<?php if (file_exists($video)){?>
<a class="videobutton" href="<?php echo $video; ?>"></a>
<?php }
else {
///
} ?>
In my opinion you missed the "{" brackets within the if statement.

wordpress nextgen gallery stray </p>

Hello i am updating a WordPress site that was riddled with errors (over 1000...-'-) now i have gotten it down to 15 or so however one page has 105 errors and they are all caused by a stray p tag that is being generated after every image here's what the code is being outputted as
<div id="ngg-image-40" class="ngg-gallery-thumbnail-box" >
<div class="ngg-gallery-thumbnail" >
<a href="a link" title="the title" class="shutterset_set_5" ><br />
<img title="01596-01_1" alt="01596-01_1" src="the src" width="100" height="75" /><br />
</a>
</div>
</p></div>
As you can see there is a p tag there for no reason, I've tried Google but got no one with a solution to this problem, I've tried looking through all the php files for the nextgen gallery and couldn't figure it out the actual code that outputs the gallery is below.
<div id="ngg-image-<?php echo $image->pid ?>" class="ngg-gallery-thumbnail-box" <?php echo $image->style ?> >
<div class="ngg-gallery-thumbnail" >
<a href="<?php echo $image->imageURL ?>" title="<?php echo $image->description ?>" <?php echo $image->thumbcode ?> >
<?php if ( !$image->hidden ) { ?>
<img title="<?php echo $image->alttext ?>" alt="<?php echo $image->alttext ?>" src="<?php echo $image->thumbnailURL ?>" <?php echo $image->size ?> />
<?php } ?>
</a>
</div>
</div>
Again as you can see there is no reference to the p tag in the above. Any and all help is appreciated.
I also did not find a solution within the gallery but I have to admit that I didn't search that well. I was lazy and fixed it with javascript as I use a custom javascript for my gallery. Maybe that helps you, too. It's MooTools btw. and assumes that the gallery div has the id "gallery":
var p = document.id('gallery').getPrevious();
if (p.get('tag') == 'p') {
p.dispose();
}

Php if empty variable statement

I'm trying to build an if statement for when a variable is filled with a url it will display a button and link to the site, and when the variable is empty the link and button will not display. So far I got it to where it is displays the button and links but making it into an if statement keeps on breaking my site. If you see a problem with the code below, please help. Thanks
<div id="social_icon">
<?php if (isset($fburl))
{
<a href="<?php echo $options['fburl']; ?>">
<img src="http://farm6.staticflickr.com/5534/9135106179_43deba3d15_o.png"" width="30"
height="30"></a>;
}
else
{
//dont show anything
}
?>
</div>
You're trying to use HTML within your PHP code, so PHP sees this as an unexpected variable/string. Either use echo for this, or close the PHP statement, and then write your HTML.
Either:
<div id="social_icon">
<?php if(isset($fburl)){ ?>
<a href="<?php echo $options['fburl']; ?>">
<img src="http://farm6.staticflickr.com/5534/9135106179_43deba3d15_o.png" width="30" height="30" />
</a>
<?php }else{
//dont show anything
} ?>
</div>
Or:
<div id="social_icon">
<?php if (isset($fburl)){
echo '<img src="http://farm6.staticflickr.com/5534/9135106179_43deba3d15_o.png" width="30" height="30" />';
}else{
//dont show anything
} ?>
</div>
Edit
Actually, I would assume it's not outputting anything because your if statement is checking for $fburl whereas you're echoing the link as $options['fburl']. If the facebook url is located at $options['fburl'], try:
<div id="social_icon">
<?php if(isset($options['fburl'])){ ?>
<a href="<?php echo $options['fburl']; ?>">
<img src="http://farm6.staticflickr.com/5534/9135106179_43deba3d15_o.png" width="30" height="30" />
</a>
<?php }else{
//dont show anything
} ?>
</div>
Edit 2
If the options are set but don't contain a link, you will also need check for that:
<div id="social_icon">
<?php if(isset($options['fburl']) && !empty($options['fburl'])){ ?>
<a href="<?php echo $options['fburl']; ?>">
<img src="http://farm6.staticflickr.com/5534/9135106179_43deba3d15_o.png" width="30" height="30" />
</a>
<?php }else{
//dont show anything
} ?>
</div>
Syntax error, change it to:
<?php if (isset($fburl))
{
//missed end tag here
?>
<a href="<?php echo $options['fburl']; ?>">
<img src="http://farm6.staticflickr.com/5534/9135106179_43deba3d15_o.png"" width="30"
height="30"></a>;
<?php
//add another php start tag
}
else
{
//dont show anything
}
?>

Calling a second image URL to realize image change function on mouseover in Magento

Aim: to realize the product image auto change on mouseover action in the category grid view in Magento.
I'll apologize first that I am no coder, so please bear with me for my silly questions.
I figured the following code with realize the image change function:
<img src="URL OF FIRST IMAGE GOES HERE" onmouseover="this.src='URL OF SECOND IMAGE GOES HERE'" onmouseout="this.src='URL OF FIRST IMAGE GOES HERE'" />
However, I will need to determine whether there is a second image for the product first, then if there is, I will need to call out the URL of the second image for the function to work.
I guess it requires a piece of php code to do that.
I'd appreciate the help from anyone with the question.
Best Regards
Liang
PS: Here's a bit more info about the page.
Variables:
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
This is the bit of code which calls out the main/first image.
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(170, 255); ?>" width="170" height="255" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
For Magento
To get OnMouseOver to change the image and show the default thumbnail in the product grid or list views, add the following code to the list.phtml file of your theme:
onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(135,135) ?>';"
onmouseout="this.src='<?phpecho $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(135,135) ?>';"
The new code will be:
<a href="<?php echo $_product->getProductUrl() ?>"
title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>"
class="product-image">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135); ?>"
width="135" height="135"
alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>"
onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(135,135) ?>';"
onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(135,135) ?>';"/>
</a>
This can get the second image,but can't resize it.
<?php $_productImage = Mage::getModel('catalog/product')->load($_product->getId());foreach ($_productImage->getMediaGalleryImages() as $image) { $_productGallery = $image->getUrl();break;};echo $_productGallery; ?>
Good luck!

If Custom Field Value exists display, if not display another Custom field value

I have a Wordpress managed web site at http://www.urbanvision.org.uk/ I have built it and everything works like I want it to and I'm happy with the outcome as it is my first fully built Wordpress web site.
I've become stuck on a request I had at the start of the week.
We have a Properties for Sale page (http://www.urbanvision.org.uk/services/property-services/properties-for-sale/) the items on this page link to PDF downloads of plans and property details. However we now have a number of properties that need to be added that link not the PDF but to an external link.
The problem I have is the page template relies on custom fields managed by the plugin Advanced Custom Fields, the field to upload the PDF is a file upload field which will take a PDF but not an URL to another page or site.
I have tried to switch the custom field to an URL rather than an upload screen but not keen on this for 2 reasons, 1) i'd have go back through the other properties and copy the url into the changed field and 2) it becomes a little more difficult for colleagues to update.
I have also tried introducing a separate a field and working out which custom field should be pulled in:
If PDF file exists in property_details pull in the URL to PDF.
If URL exists in property_details_url pull in URL entered.
There are two parts of each post that need to link to further details (PDF or external URL). They are the thumbnail image and the view details link.
The code I had before (just linking to the PDF):
<?php
$featuredPosts = new WP_Query();
$featuredPosts->query('showposts=20&cat=13');
while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?>
<div class="literaturedescription">
<a href="<?php the_field('property_details'); ?>" title="<?php the_field('property_title'); ?>">
<img src="<?php the_field('property_thumbnail'); ?>" width="220px" height="150px" alt="<?php the_field('property_title'); ?>" /></a>
<p><strong><?php the_field('property_title'); ?></strong><br /><?php the_field('property_excerpt'); ?> <span style="color:red;font-weight:bold;"><?php the_field('property_status'); ?></span>
<br />> > View Details</p><br />
The Code I have changed it to (still can't get it to work):
<?php $featuredPosts = new WP_Query();
$featuredPosts->query('showposts=20&cat=12');
while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?>
<div class="literaturedescription">
<a href="<?php the_field('property_details'); ?>" title="<?php the_field('property_title'); ?>">
<img src="<?php the_field('property_thumbnail'); ?>" width="220px" height="150px" alt="<?php the_field('property_title'); ?>" /></a>
<p><strong><?php the_field('property_title'); ?></strong><br /><?php the_field('property_excerpt'); ?> <span style="color:red;font-weight:bold;"><?php the_field('property_status'); ?></span>
<?php if(get_field('property_details_url')){ ?>
<br />> > View Details</p><br />
<?php } else { ?>
<br />> > View Details</p><br />
<?php } ?>
I also had a look at pulling directly from the MySQL database that Wordpress is using but really struggled to get the page to display without error.
As always, any help would be greatly appreciated.
your on the right track, but what to do is assign your customfield to a variable.
ie:
<?php
$prop_det_url = get_field('property_details_url');
if($prop_det_url!=''){ ?>
<br />> > View Details</p><br />
<?php } else { ?>
<br />> > View Details</p><br />
<?php } ?>
hopefully the check should fine that the property_details_url has somthing other than nothing, it will show the link, if not it will show the other piece of code?
Marty

Categories