I have these bits here that will display a google map link for me. How can I wrap this in some sort of if statemnt that will check to see if there is ANY data in $event['where']. I don't want the link to display when there is no data.
<a title="See on Map" target="_blank" href="http://maps.google.com/maps?q=<?php echo $event['where']; ?>">See on map</a>
<?php if(!empty($event)){ ?> <a title="See on Map" target="_blank" href="http://maps.google.com/maps?q=<?php echo $event['where']; ?>">See on map</a> <?php } ?>
Try this:
<?php echo (!empty($event['where'])) ? $event['where'] : ""; ?>
Well isset() will determine if a variable/object is set and is not null
if(isset($event['where'])){
//...
}
http://php.net/manual/en/function.isset.php
The following will not show the link if $event['where'] is not set, is null, is blank (""), is false or is 0 - I think it is what you want:
<?php
if (!empty($event['where'])) {
?>
<a title="See on Map" target="_blank" href="http://maps.google.com/maps?q=<?php echo $event['where']; ?>">See on map</a>
<?php
}
?>
Related
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.
i have a question.
I have this code to get an profile name as an link.
<a href=<?php echo $userpro->permalink( get_the_author_meta('ID') );
?>><?php echo $user_id=get_the_author_meta('display_name');?></a>
The link isnt clickable. I am a newbie in coding.
So maybe somebody can help me :)
Greetings
Try this:
<a href="<?php echo $userpro->permalink(get_the_author_meta('ID')); ?>">
<?php echo get_the_author_meta('display_name'); ?>
</a>
If it doesnt work... please supply the value and initialisation of $userpro!
I'm trying to display a link only if it has a value.
How can i get the image if the_field imdb is not empty?
<a href="<?php the_field('imdb'); ?>" >
<img style="width:60px;"src="/img/link.png" /></a>
Use get_field(); instead of the_filed();.
if(!empty(get_field("fildname"))){
#your code hear
}
Try:-
if(!empty(the_field('imdb'))){
<a href="<?php the_field('imdb'); ?>" ><img style="width:60px;"src="/img/link.png" /></a>
}
Use isset
if(isset(the_field('imdb'))&&!empty(the_field('imdb'))){
<img src=""/>
}
Since i didnt want to show the img or link on older posts i solved it by:
<?php
// assign image
$imdbimg = "<img src='http://mydomain.com/IMDb.png' class='imdb' />";
// imdb link from custom field
$imdblink = get_field('imdb');
?>
// display img and link on post newer then id 16
<?php global $post;
if ( $post->ID >= 16 ){
echo ' ' . $imdbimg . '';
}
?>
The link page:
<a href="displayProduct.php?productID=<?php'.$pID.'?>">
The displayProduct.php page:
<?php
echo $_GET["productID"];
?>
This is my tester, to see if clicking on the link will pass the data from page 1 to displayProduct page.
It successfully passes the variable in the ' URL ' bar but the echo does not display that variable.
Am I missing something?
You missed an echo and have some weird concatenation.
<a href="displayProduct.php?productID=<?php'.$pID.'?>">
should be:
<a href="displayProduct.php?productID=<?php echo $pID; ?>">
<a href="<?php echo 'displayProduct.php?productID=' . $pID; ?>">
The shortest way:
<a href="displayProduct.php?productID=<?php echo $pID ?>">
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
}
?>