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条)

报告相同问题?

悬赏问题

  • ¥20 matlab如何绘制三维瀑布图
  • ¥15 关于用abap来解决动态规划的问题,但是要求输出索引值,这个是难点
  • ¥15 在ISIS中什么是IP从地址
  • ¥15 压测时,并发量过高时,响应时间出现尖刺
  • ¥15 关于vmprotect3.8.4虚拟文件一项
  • ¥15 在不用IT调试的情况下怎样能连外网
  • ¥20 C#调用虚拟键盘TabTip.exe
  • ¥15 Qt4代码实现下面的界面
  • ¥15 CCS离散化传递函数与仿真不一致
  • ¥15 prism提示我reinstall prism 如何解决