Skip to content

Commit

Permalink
Avoid going in and out of PHP unnecessarily.
Browse files Browse the repository at this point in the history
Closes Automattic#854

Includes minor alignment changes for easier readability/detection of start/end of conditions.
  • Loading branch information
jrfnl committed Nov 11, 2015
1 parent 6f6de25 commit 8470f55
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 109 deletions.
19 changes: 12 additions & 7 deletions 404.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
<div class="page-content">
<p><?php esc_html_e( 'It looks like nothing was found at this location. Maybe try one of the links below or a search?', '_s' ); ?></p>

<?php get_search_form(); ?>
<?php
get_search_form();

the_widget( 'WP_Widget_Recent_Posts' );

<?php the_widget( 'WP_Widget_Recent_Posts' ); ?>
if ( _s_categorized_blog() ) : // Only show the widget if site has multiple categories.
?>

<?php if ( _s_categorized_blog() ) : // Only show the widget if site has multiple categories. ?>
<div class="widget widget_categories">
<h2 class="widget-title"><?php esc_html_e( 'Most Used Categories', '_s' ); ?></h2>
<ul>
Expand All @@ -39,20 +42,22 @@
?>
</ul>
</div><!-- .widget -->
<?php endif; ?>

<?php
endif;

/* translators: %1$s: smiley */
$archive_content = '<p>' . sprintf( esc_html__( 'Try looking in the monthly archives. %1$s', '_s' ), convert_smilies( ':)' ) ) . '</p>';
the_widget( 'WP_Widget_Archives', 'dropdown=1', "after_title=</h2>$archive_content" );
?>

<?php the_widget( 'WP_Widget_Tag_Cloud' ); ?>
the_widget( 'WP_Widget_Tag_Cloud' );
?>

</div><!-- .page-content -->
</section><!-- .error-404 -->

</main><!-- #main -->
</div><!-- #primary -->

<?php get_footer(); ?>
<?php
get_footer();
38 changes: 19 additions & 19 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">

<?php if ( have_posts() ) : ?>
<?php
if ( have_posts() ) : ?>

<header class="page-header">
<?php
Expand All @@ -21,31 +22,30 @@
?>
</header><!-- .page-header -->

<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();

<?php

/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );
?>
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );

<?php endwhile; ?>
endwhile;

<?php the_posts_navigation(); ?>
the_posts_navigation();

<?php else : ?>
else :

<?php get_template_part( 'template-parts/content', 'none' ); ?>
get_template_part( 'template-parts/content', 'none' );

<?php endif; ?>
endif; ?>

</main><!-- #main -->
</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
get_sidebar();
get_footer();
25 changes: 14 additions & 11 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

<div id="comments" class="comments-area">

<?php // You can start editing here -- including this comment! ?>

<?php if ( have_comments() ) : ?>
<?php
// You can start editing here -- including this comment!
if ( have_comments() ) : ?>
<h2 class="comments-title">
<?php
printf( // WPCS: XSS OK.
Expand Down Expand Up @@ -66,17 +66,20 @@

</div><!-- .nav-links -->
</nav><!-- #comment-nav-below -->
<?php endif; // Check for comment navigation. ?>
<?php
endif; // Check for comment navigation.

<?php endif; // Check for have_comments(). ?>
endif; // Check for have_comments().


// If comments are closed and there are comments, let's leave a little note, shall we?
if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) : ?>

<?php
// If comments are closed and there are comments, let's leave a little note, shall we?
if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
?>
<p class="no-comments"><?php esc_html_e( 'Comments are closed.', '_s' ); ?></p>
<?php endif; ?>
<?php
endif;

<?php comment_form(); ?>
comment_form();
?>

</div><!-- #comments -->
9 changes: 6 additions & 3 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@

<header id="masthead" class="site-header" role="banner">
<div class="site-branding">
<?php if ( is_front_page() && is_home() ) : ?>
<?php
if ( is_front_page() && is_home() ) : ?>
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<?php else : ?>
<p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
<?php endif;
<?php
endif;

$description = get_bloginfo( 'description', 'display' );
if ( $description || is_customize_preview() ) : ?>
<p class="site-description"><?php echo $description; /* WPCS: xss ok. */ ?></p>
<?php endif; ?>
<?php
endif; ?>
</div><!-- .site-branding -->

<nav id="site-navigation" class="main-navigation" role="navigation">
Expand Down
2 changes: 1 addition & 1 deletion inc/extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function _s_body_classes( $classes ) {
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}

// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
Expand Down
41 changes: 21 additions & 20 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,40 @@
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">

<?php if ( have_posts() ) : ?>
<?php
if ( have_posts() ) :

<?php if ( is_home() && ! is_front_page() ) : ?>
if ( is_home() && ! is_front_page() ) : ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php endif; ?>

<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
endif;

<?php
/* Start the Loop */
while ( have_posts() ) : the_post();

/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );
?>
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );

<?php endwhile; ?>
endwhile;

<?php the_posts_navigation(); ?>
the_posts_navigation();

<?php else : ?>
else :

<?php get_template_part( 'template-parts/content', 'none' ); ?>
get_template_part( 'template-parts/content', 'none' );

<?php endif; ?>
endif; ?>

</main><!-- #main -->
</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
get_sidebar();
get_footer();
23 changes: 12 additions & 11 deletions page.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">

<?php while ( have_posts() ) : the_post(); ?>
<?php
while ( have_posts() ) : the_post();

<?php get_template_part( 'template-parts/content', 'page' ); ?>
get_template_part( 'template-parts/content', 'page' );

<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;

<?php endwhile; // End of the loop. ?>
endwhile; // End of the loop.
?>

</main><!-- #main -->
</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
get_sidebar();
get_footer();
25 changes: 13 additions & 12 deletions search.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,37 @@
<section id="primary" class="content-area">
<main id="main" class="site-main" role="main">

<?php if ( have_posts() ) : ?>
<?php
if ( have_posts() ) : ?>

<header class="page-header">
<h1 class="page-title"><?php printf( esc_html__( 'Search Results for: %s', '_s' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
</header><!-- .page-header -->

<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();

<?php
/**
* Run the loop for the search to output the results.
* If you want to overload this in a child theme then include a file
* called content-search.php and that will be used instead.
*/
get_template_part( 'template-parts/content', 'search' );
?>

<?php endwhile; ?>
endwhile;

<?php the_posts_navigation(); ?>
the_posts_navigation();

<?php else : ?>
else :

<?php get_template_part( 'template-parts/content', 'none' ); ?>
get_template_part( 'template-parts/content', 'none' );

<?php endif; ?>
endif; ?>

</main><!-- #main -->
</section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
get_sidebar();
get_footer();
25 changes: 13 additions & 12 deletions single.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">

<?php while ( have_posts() ) : the_post(); ?>
<?php
while ( have_posts() ) : the_post();

<?php get_template_part( 'template-parts/content', 'single' ); ?>
get_template_part( 'template-parts/content', 'single' );

<?php the_post_navigation(); ?>
the_post_navigation();

<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;

<?php endwhile; // End of the loop. ?>
endwhile; // End of the loop.
?>

</main><!-- #main -->
</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
get_sidebar();
get_footer();
13 changes: 8 additions & 5 deletions template-parts/content-none.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@
</header><!-- .page-header -->

<div class="page-content">
<?php if ( is_home() && current_user_can( 'publish_posts' ) ) : ?>
<?php
if ( is_home() && current_user_can( 'publish_posts' ) ) : ?>

<p><?php printf( wp_kses( __( 'Ready to publish your first post? <a href="%1$s">Get started here</a>.', '_s' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( admin_url( 'post-new.php' ) ) ); ?></p>

<?php elseif ( is_search() ) : ?>

<p><?php esc_html_e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', '_s' ); ?></p>
<?php get_search_form(); ?>
<?php
get_search_form();

<?php else : ?>
else : ?>

<p><?php esc_html_e( 'It seems we can&rsquo;t find what you&rsquo;re looking for. Perhaps searching can help.', '_s' ); ?></p>
<?php get_search_form(); ?>
<?php
get_search_form();

<?php endif; ?>
endif; ?>
</div><!-- .page-content -->
</section><!-- .no-results -->
3 changes: 2 additions & 1 deletion template-parts/content-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
</header><!-- .entry-header -->

<div class="entry-content">
<?php the_content(); ?>
<?php
the_content();

wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', '_s' ),
'after' => '</div>',
Expand Down
Loading

0 comments on commit 8470f55

Please sign in to comment.