Last active
September 2, 2016 02:14
-
-
Save joelstransky/5c0f3086f4599b6d5ad10877c990c791 to your computer and use it in GitHub Desktop.
PHP: scope of global keyword
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: My Page Template | |
*/ | |
?> | |
<?php // the_post() already uses `global $post;`, so why is it needed again on line 11 in content-my_page.php? ?> | |
<?php while (have_posts()) : the_post(); ?> | |
<?php get_template_part('templates/page', 'header'); ?> | |
<?php get_template_part('templates/content', 'my_page'); ?> | |
<?php endwhile; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row"> | |
<div class="content-main"> | |
<?php | |
// check if the flexible content field has rows of data | |
if( have_rows('flexible_blocks') ): | |
// loop through the rows of data | |
while ( have_rows('flexible_blocks') ) : $row = the_row(); | |
switch (get_row_layout()) { | |
case 'inserted_content': | |
global $post; // <-- Why is this required in order the following call to post_class() to work? | |
$post = get_post( get_sub_field('inserted_item') ); | |
setup_postdata( $post ); | |
?> | |
<article <?php post_class(); ?>> | |
<div class="aggregate-main"> | |
<?php vpa_render_post_object( $post ); ?> | |
</div> | |
<?php if ( embedded_has_supplemental($row) ) : ?> | |
<aside class="sidebar"> | |
<?php acf_the_supplemental( $post->ID ); ?> | |
</aside> | |
<?php endif; ?> | |
</article> | |
<?php | |
break; | |
default: | |
# code... | |
break; | |
} | |
endwhile; | |
reset_rows(); | |
else : | |
// no layouts found | |
endif; | |
?> | |
</div> | |
</div> <!-- .row --> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment