无法理解 code/functions in header.php in Twenty-14 theme in wordpress
unable to understand code/functions in header.php in Twenty Fourteen theme in wordpress
我是 wordpress 新手。我在理解 wordpress 二十十四主题中编写的代码时遇到了问题。在 header.php 的正文中有一些我无法理解的代码,比如他们所做的
<?php if ( get_header_image() ) : ?>
<div id="site-header">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
</a>
</div>
<?php endif; ?>
请有人帮我理解这段代码的作用
<?php if ( get_header_image() ) : ?>
这是因为如果你为你的主题设置了横幅图片,你可以通过自定义主题进行更改,并更改或删除如下图所示,通过管理面板转到外观 > 自定义,然后它将带你进入自定义页面如图所示在那里你会发现 Header Image.
<div id="site-header">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
</a>
</div>
所以在这段代码中,如果找到 header 图片,它将自动设置在 <img>
中,它的 alt
将被设置为站点 NAME 并且高度或宽度将设置为主题默认 CSS。 <img>
之前的 <a>
用于主页的前导 link。
我是 wordpress 新手。我在理解 wordpress 二十十四主题中编写的代码时遇到了问题。在 header.php 的正文中有一些我无法理解的代码,比如他们所做的
<?php if ( get_header_image() ) : ?>
<div id="site-header">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
</a>
</div>
<?php endif; ?>
请有人帮我理解这段代码的作用
<?php if ( get_header_image() ) : ?>
这是因为如果你为你的主题设置了横幅图片,你可以通过自定义主题进行更改,并更改或删除如下图所示,通过管理面板转到外观 > 自定义,然后它将带你进入自定义页面如图所示在那里你会发现 Header Image.
<div id="site-header">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
</a>
</div>
所以在这段代码中,如果找到 header 图片,它将自动设置在 <img>
中,它的 alt
将被设置为站点 NAME 并且高度或宽度将设置为主题默认 CSS。 <img>
之前的 <a>
用于主页的前导 link。