Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link
<?php
 $child_pages = pp_get_child_pages();
 if ( count( $child_pages ) != 0 ) :
 $empty_child_pages = array();
 echo '<div class="row quick-links page-links primary-content-item">';
 foreach ( $child_pages as $post ) :
 setup_postdata( $post );
 if ( $post->post_content == "" ) {
 $empty_child_pages[] = $post;
 continue;
 }
 pp_get_template_part( 'content', 'child-page' );
 endforeach;
 foreach ( $empty_child_pages as $post ) :
 setup_postdata( $post );
 pp_get_template_part( 'content', 'child-page' );
 endforeach;
 echo '</div>';
 endif;
 wp_reset_postdata();
?>
<?php
 $child_pages = pp_get_child_pages();
 if ( count( $child_pages ) != 0 ) :
 $empty_child_pages = array();
 echo '<div class="row quick-links page-links primary-content-item">';
 foreach ( $child_pages as $post ) :
 setup_postdata( $post );
 if ( $post->post_content == "" ) {
 $empty_child_pages[] = $post;
 continue;
 }
 pp_get_template_part( 'content', 'child-page' );
 endforeach;
 foreach ( $empty_child_pages as $post ) :
 setup_postdata( $post );
 pp_get_template_part( 'content', 'child-page' );
 endforeach;
 echo '</div>';
 endif;
 wp_reset_postdata();
?>
<?php
 $child_pages = pp_get_child_pages();
 if ( count( $child_pages ) != 0 ) :
 $empty_child_pages = array();
 echo '<div class="row quick-links page-links primary-content-item">';
 foreach ( $child_pages as $post ) :
 setup_postdata( $post );
 if ( $post->post_content == "" ) {
 $empty_child_pages[] = $post;
 continue;
 }
 pp_get_template_part( 'content', 'child-page' );
 endforeach;
 foreach ( $empty_child_pages as $post ) :
 setup_postdata( $post );
 pp_get_template_part( 'content', 'child-page' );
 endforeach;
 echo '</div>';
 endif;
 wp_reset_postdata();
?>
Source Link
Der Kommissar
  • 20.2k
  • 4
  • 70
  • 158

The biggest change I would make, speaking from a semantics standpoint, is to limit your whitespace and use consistent control structures. I.e. take

<?php
 $child_pages = pp_get_child_pages();
 if ( count( $child_pages ) != 0 ) :
 $empty_child_pages = array();
 echo '<div class="row quick-links page-links primary-content-item">';
 foreach ( $child_pages as $post ) :
 setup_postdata( $post );
 if ( $post->post_content == "" ) {
 $empty_child_pages[] = $post;
 continue;
 }
 pp_get_template_part( 'content', 'child-page' );
 endforeach;
 foreach ( $empty_child_pages as $post ) :
 setup_postdata( $post );
 pp_get_template_part( 'content', 'child-page' );
 endforeach;
 echo '</div>';
 endif;
 wp_reset_postdata();
?>

And write it more semantically:

<?php
 $child_pages = pp_get_child_pages();
 if ( count( $child_pages ) != 0 )
 {
 $empty_child_pages = array();
 echo '<div class="row quick-links page-links primary-content-item">';
 foreach ( $child_pages as $post )
 {
 setup_postdata( $post );
 if ( $post->post_content == "" )
 {
 $empty_child_pages[] = $post;
 continue;
 }
 pp_get_template_part( 'content', 'child-page' );
 }
 foreach ( $empty_child_pages as $post )
 {
 setup_postdata( $post );
 pp_get_template_part( 'content', 'child-page' );
 }
 echo '</div>';
 }
 wp_reset_postdata();
?>

In my opinion, this makes it far easier to follow along with.

lang-php

AltStyle によって変換されたページ (->オリジナル) /