Created
February 3, 2015 17:21
-
-
Save devinsays/705f9e9de5cd2a9cb16f to your computer and use it in GitHub Desktop.
Display Page Selection in Template
This file contains hidden or 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 | |
// Get pages set in the customizer (if any) | |
$pages = array(); | |
for ( $count = 1; $count <= 5; $count++ ) { | |
$mod = get_theme_mod( 'showcase-page-' . $count ); | |
if ( 'page-none-selected' != $mod ) { | |
$pages[] = $mod; | |
} | |
} | |
$args = array( | |
'posts_per_page' => 5, | |
'post_type' => 'page', | |
'post__in' => $pages, | |
'orderby' => 'post__in' | |
); | |
$query = new WP_Query( $args ); | |
if ( $query->have_posts() ) : | |
$count = 1; | |
while ( $query->have_posts() ) : $query->the_post(); | |
?> | |
<article id="post-<?php the_ID(); ?>" <?php post_class( 'featured-' . $count ); ?>> | |
<header class="entry-header"> | |
<?php the_title( sprintf( '<h1 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h1>' ); ?> | |
</header><!-- .entry-header --> | |
<div class="entry-summary clearfix"> | |
<?php the_excerpt(); ?> | |
</div><!-- .entry-content --> | |
<?php endif; ?> | |
</article><!-- #post-## --> | |
<?php | |
$count++; | |
endwhile; | |
else : | |
if ( current_user_can( 'customize' ) ) { ?> | |
<div class="message"> | |
<p><?php _e( 'There are no pages available to display.', 'textdomain' ); ?></p> | |
<p><?php printf( | |
__( 'These pages can be set in the <a href="%s">customizer</a>.', 'textdomain' ), | |
admin_url( 'customize.php?autofocus[control]=showcase' ) | |
); ?> | |
</p> | |
</div> | |
<?php } | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the tutorial!
Looks like line 34
<?php endif; ?>
shouldn't be in there?I also changed line 36 to
</article><!-- #post-<?php the_ID(); ?> -->
Finally, I'm not sure about the first bit of code, where does
page-none-selected
come from? For me I'm getting0
if I don't select anything. The tutorial doesn't inject any default values in when the customizer is setup and it doesn't seem to be a part of WordPress.