duandunzhuo3234 2013-03-12 04:04
浏览 55
已采纳

PHP If和Else语句在Wordpress中

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>';
}

?>
  • 写回答

2条回答 默认 最新

  • dtkjthe4025 2013-03-12 04:12
    关注

    it should be

    echo'<img src="';
    global $data; 
    $data[0]['media_upload']; 
          ^ // you forgot 0th index
    echo'" /></a>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件