Last active
November 29, 2018 20:29
-
-
Save sophiawzey/77ec9179320cea46c747e6cac569a26e to your computer and use it in GitHub Desktop.
[Top Level Listing Logic] #wordpress
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 part for displaying page content in page-top-level-listing.php | |
*/ | |
?> | |
<article id="post-<?php the_ID(); ?>" <?php post_class( '' ); ?> role="article" itemscope | |
itemtype="http://schema.org/WebPage"> | |
<?php get_template_part('parts/breadcrumbs'); ?> | |
<!-- banner/ header here --> | |
<section class="teasers"> | |
<div class="grid-container"> | |
<?php | |
$args = array( | |
'post_type' => 'page', | |
'posts_per_page' => - 1, //not sure why this is negative 1 but it works | |
'post_parent' => $post->ID, | |
'order' => 'ASC', | |
'orderby' => 'menu_order' | |
); | |
$parent = new WP_Query( $args ); | |
if ( $parent->have_posts() ) : ?> | |
<?php while ( $parent->have_posts() ) : $parent->the_post(); ?> | |
<?php | |
$img = get_field( 'teaser_image' ); | |
$teaser = get_field( 'teaser_body_copy' ); | |
$teaserTitle = get_the_title(); | |
$cta = get_field( 'teaser_button_text' ); | |
if ( $img ) { | |
$imgUrl = $img['url']; | |
} else { | |
$imgUrl = '/wp-content/uploads/2018/10/Y-Axis-Milling.jpg'; | |
} | |
?> | |
<div id="teaser-<?php the_ID(); ?>" class="teaser"> | |
<a href="<?php the_permalink(); ?>" title="<?php echo $teaserTitle ?>"> | |
<div class="teaser__wrapper grid-x"> | |
<div class="teaser__image cell large-8" | |
style="background:url(<?= $imgUrl ?>) no-repeat center; background-size:cover;"></div> | |
<div class="teaser__text cell large-4"> | |
<h3 class="teaser__title"><?php echo $teaserTitle ?></h3> | |
<div class="teaser__body"> | |
<?php echo $teaser ?> | |
<div class="button"><?php echo $cta ?><span class="fas fa-chevron-right"></span> | |
</div> | |
</div> | |
</div> | |
</div> | |
</a> | |
</div> | |
<?php endwhile; ?> | |
<?php endif; | |
wp_reset_postdata(); ?> | |
</div> | |
</section> | |
<footer class="article-footer"> | |
<?php // wp_link_pages(); ?> | |
</footer> <!-- end article footer --> | |
</article> <!-- end article --> |
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: Top Level Listing | |
*/ | |
get_header(); ?> | |
<div class="content"> | |
<div class="inner-content grid-x grid-margin-x"> | |
<main class="main cell" role="main"> | |
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> | |
<?php get_template_part( 'parts/page', 'top-level-listing' ); ?> | |
<?php endwhile; endif; ?> | |
</main> <!-- end #main --> | |
<?php // get_sidebar(); ?> | |
</div> <!-- end #inner-content --> | |
</div> <!-- end #content --> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment