有人可以解释这个 PHP 代码吗?

Can someone explain this PHP code?

    <h1 class="site-title">
       <a href="<?php echo esc_url( home_url( '/' ) ); ?>" 
       rel="home"><?php bloginfo( 'name' ); ?>
       </a>
    </h1>
    if (is_category('Ponies')) { ?>
      // overlay a pretty rainbow on the logo for the ponies category
       <img id="rainbow"
          src='<?php bloiginfo('template_directory');?>/img/rainbow.png" 
          alt="OMG! Ponies! " />
    <?php  } ?>

我无法匹配 PHP 标签。代码的注释说 "Now any time the category of the content is Ponies, your header also includes the rainbow.png." 但很清楚这是如何发生的。实际代码在 Williams 的 WordPress Design and Developement 的 p245 上。感谢您再次关注它。

"If" 不在 <?php ... ?> 内。必须是:

<?php if (is_category('Ponies')) { ?>

当中间有 HTML 时,我更喜欢使用 <?php if (condition): ?>。 但无论如何...

1) if() 语句需要在 php 标签内。

2) 您不需要 echo 来检索博客信息。

bloginfo() documentation

3) 您在底部拼错了 bloginfo...

我的代码:

<h1 class="site-title">
   <a href="<?php echo esc_url(home_url('/')); ?>" rel="home">
      <?php $bloginfo('name'); ?>
   </a>
</h1>

<?php if (is_category('Ponies')) : ?>
    <img id="rainbow"
         src="<?php get_bloginfo('template_directory') . '/img/rainbow.png'; ?>"
         alt="OMG! Ponies!" />
<?php endif; ?>