Reputation: 569
I'm trying to figure out how to do a if else statement in Wordpress. I want it to state if $data[0]['media_upload']
is empty then show the blog title. Else (if there is something there) show the logo in Wordpress. I'm wondering if I have the wrong syntax.
Right now I have the following which is showing the blog title and no errors but I do have a image uploaded and its not showing for some reason. Any ideas would be great!
<?php
if (empty($data[0]['media_upload'])) {
echo'<h1 class="site-title"><a href="';
esc_url( home_url( '/' ) );
echo'" title="';
esc_attr( get_bloginfo( 'name', 'display' ) );
echo'" rel="home">';
bloginfo( 'name' );
echo'</a></h1>';
}
else{
echo '<a href="';
bloginfo('siteurl');
echo '">';
echo'<img src="';
global $data;
$data['media_upload'];
echo'" /></a>';
}
?>
Upvotes: 0
Views: 515
Reputation: 356
Try changing:
$data['media_upload'];
in your else to: $data[0]['media_upload'];
like you have in your if statement (or the other way around). We don't really know what $data is so it's hard to help you.
Edit: Since I can't comment yet, I'll comment here. Try using the rubber duck technique; explain to us what is happening with the $data object in your code. Maybe you'll figure it out yourself.
Upvotes: 2
Reputation: 30488
it should be
echo'<img src="';
global $data;
$data[0]['media_upload'];
^ // you forgot 0th index
echo'" /></a>';
Upvotes: 0