In the footer-menus-widgets.php template, from Twenty Twenty theme (by Automatic), we can find a way to code a template and call functions that uses variables to store the result of functions like has_nav_menu()
or is_active_sidebar()
and then use it later in the template in an if structure if ( $has_footer_menu)
instead of using directly the function itself. Here is the code (i've shortened it) :
<?php
/**
* Displays the menus and widgets at the end of the main element.
*/
$has_footer_menu = has_nav_menu( 'footer' );
$has_social_menu = has_nav_menu( 'social' );
$has_sidebar_1 = is_active_sidebar( 'sidebar-1' );
$has_sidebar_2 = is_active_sidebar( 'sidebar-2' );
if ( $has_footer_menu || $has_social_menu || $has_sidebar_1 || $has_sidebar_2 ) {
?>
<div>
<?php if ( $has_footer_menu || $has_social_menu ) { ?>
<div class="footer-top">
<?php if ( $has_footer_menu ) { ?>
<nav role="navigation">
<!-- some code… -->
</nav><!-- .site-nav -->
<?php } ?>
<?php if ( $has_social_menu ) { ?>
<nav role="navigation">
<!-- some code… -->
</nav><!-- .footer-social-wrapper -->
<?php } ?>
</div><!-- .footer-top -->
<?php } ?>
<?php if ( $has_sidebar_1 || $has_sidebar_2 ) { ?>
<aside>
<div>
<?php if ( $has_sidebar_1 ) { ?>
<div>
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div>
<?php } ?>
<?php if ( $has_sidebar_2 ) { ?>
<div>
<?php dynamic_sidebar( 'sidebar-2' ); ?>
</div>
<?php } ?>
</div><!-- .footer-widgets-wrapper -->
</aside><!-- .footer-widgets-outer-wrapper -->
<?php } ?>
</div>
<?php } ?>
But in Twenty Seventeen footer-widgets.php template file, we only find the functions :
<?php
if ( is_active_sidebar( 'sidebar-2' ) ||
is_active_sidebar( 'sidebar-3' ) ) :
?>
<aside class="widget-area" role="complementary" aria-label="<?php esc_attr_e( 'Footer', 'twentyseventeen' ); ?>">
<?php
if ( is_active_sidebar( 'sidebar-2' ) ) {
?>
<div class="widget-column footer-widget-1">
<?php dynamic_sidebar( 'sidebar-2' ); ?>
</div>
<?php
}
if ( is_active_sidebar( 'sidebar-3' ) ) {
?>
<div class="widget-column footer-widget-2">
<?php dynamic_sidebar( 'sidebar-3' ); ?>
</div>
<?php } ?>
</aside><!-- .widget-area -->
<?php endif; ?>
My question is : why are they coded differently ? Does the Twenty Twenty template increase the performance of the code (decreasing the resources consumed, the page speed) ? Meaning : is it a better way of coding to store the result of a function like has_nav_menu()
in a variable like in Twenty Twenty? Or is it only about maintainability and readability of code ?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744856164a4597418.html
评论列表(0条)